5

I'm trying to create a module tag but it just isn't working, I'm following the Hello World tutorial at Ellis Lab. My module is installed and the MCP part is working. Here is my mod file:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Facebook_Photos {

    public $return_data = "";

    // Constructor
    public function __construct()
    {
        $this->EE =& get_instance();
        $this->return_data = 'Hello World';
        return $this->return_data;
    }

    public function get_photos()
    {
        $this->return_data = 'Hello World';
    }
}

?>

Just in case here is my tag pair in my template (it's the only template that exists):

{exp:facebook_photos:get_photos}

I’m getting the following error from EE:

The following tag cannot be processed:

{exp:facebook_photos:get_photos}

Please check that the ‘facebook_photos’ module is installed and that ‘get_photos’ is an available method of the module

3
  • 1
    Can you restructure your question to include the full module class code? It's really hard to see what's going on. Is get_photos in your Facebook_photos class? PS I highly doubt it's anything to do with your language file. Jan 14, 2013 at 5:09
  • Thanks for the thought - I figured it out and posted the answer below. Jan 14, 2013 at 5:14
  • 1
    I just reformatted your question to make it more clear what the actual problem was. In the future, try to format your questions so that it’s clear what the issue is, even to people who haven’t been involved in the thread, so that it might help someone else with the same issue. Jan 14, 2013 at 14:37

2 Answers 2

8

The ‘p’ in your module’s class name must be lowercased.

From http://ellislab.com/expressionengine/user-guide/development/modules.html#the-core-module-file-mod-module-name-php:

The Core Module file is used for outputting content via Templates and doing any processing that is required by both the Control Panel and any module tags contained in a template. It includes a class with a name that matches the package (the first letter of the class name must be capitalized).

2

Ok, finally got it - took me forever but now I can hopefully help someone else that runs into this.

I checked that my mod.facebook_photos.php had the method get_photos and that everything was spelled right and it was. So I thought I'd check if it was installed, it was - but at the same time it wasn't.

If you open system/expressionengine/libraries/Template.php and go to line 1224 you find the conditional that is causing the error. There I placed some debugging information:

echo 'Class Name: ' . $class_name . '<br/>';
echo 'Tag Data Class: <br/>';
var_dump($this->tag_data[$i]['class']);
echo '<br/>Modules: <br/>';
var_dump($this->modules);
echo '<br/>Module Data Class Name: <br/>';
var_dump($this->module_data[$class_name]);

Everything came back as expected except for the last one that threw a PHP error where it couldn't find that index. So I echoed out the $class_name and I received Facebook_photos. To my surprise on line 1205 you see the following:

$class_name = ucfirst($this->tag_data[$i]['class']);

So what I did was go to my upd.facebook_photos.php and renamed every place that Facebook_Photos to Fbphotos (I removed the underscores to create a shorter namespace). I then renamed all file names and class names to match this new namespace making sure that the class names have the first letter uppercased (as that is what ucfirst) does.

Also, my tag pair had to change due to the new namespace - it now looks like this:

{exp:fbphotos:get_photos}

Now the get_photos method works as expected. Hope this helps someone else!

4
  • 1
    Maybe it was expecting Facebook_photos instead of Facebook_Photos? I didn't think PHP class names were case sensitive though. Glad you solved it, thanks for posting the solution! Jan 14, 2013 at 5:17
  • I don't think that they are case sensitive, but when they're doing an in_array check that's what's throwing the error. Jan 14, 2013 at 5:29
  • Brandon Kelly's response above is correct. Case sensitivity is built-in. Not a bug. I just wanted to make sure that was noted. Jan 14, 2013 at 15:46
  • Yeah, I was posting my findings at the same time he was posting his response. They basically got published at the same time, sorry for the redundancy. Jan 14, 2013 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.