ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Can't call $this->EE from within php functions in templates

December 16, 2011 10:12am

Subscribe [2]
  • #1 / Dec 16, 2011 10:12am

    Trend Hunter

    81 posts

    Hi,

    I have php code (and thus functions) within templates in my EE application. After upgrading to 2.3 and changing some calls like $DB->query to $this->EE->db->query(), there are issues within functions.

    For instance, within functions I am unable to reference the global EE object ($this->EE) due to the obvious scope issue.

    Is anyone aware of a best practice for dealing with this?

    Thanks!

  • #2 / Dec 16, 2011 2:36pm

    Rob Sanchez

    335 posts

    In your functions you can do:

    function some_custom_function
    {
        $EE =& get_instance();
    
        $EE->db->query('SELECT * FROM exp_table');
    }
  • #3 / Dec 18, 2011 8:25am

    Sean C. Smith

    3818 posts

    Trend,

    Did your Rob’s code help you?

    Rob, thanks for the assist.

    Sean

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases