1

So i'm looking at http://ellislab.com/expressionengine/user-guide/development/usage/database.html

I've used

$query = $this->EE->db->query("SELECT channel_name FROM exp_channels");

many times, but never within a class. and using $this-> causes issues. I'm no expert but how do i overcome this?

class Name
{
    public $variable;

    public function Something()
    {
         if($this->variable == "whatever")
           {
                //Run query to pull data based on $variable
                // This causes errors. I assume because $this is now something else.
                $this->EE->db->query("SELECT * FROM tablename WHERE...");
           }
    }
}

Message: Undefined property: Module::$EE

Message: Trying to get property of non-object

Fatal error: Call to a member function query() on a non-object

2

You first need to initialize global object like:

$this->EE =& get_instance();
  • Is this in the user guide somewhere? – ipixel Apr 12 '13 at 16:11
  • It's mentioned in the addon dev docs and is used if you're building a plugin, extension, or module. It just makes a local reference to the EE super object. – Ian Apr 12 '13 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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