We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How can PHP in a template write to the EE errorlog?

Development and Programming

Michael C. (ProImage)'s avatar
Michael C. (ProImage)
102 posts
15 years ago
Michael C. (ProImage)'s avatar Michael C. (ProImage)

EE 1.70

I’ve got a bit of custom PHP scripting in a template, and there’s a certain condition that - if it occurs - I want to know about it. In pseudo-script:

if ($x == $bad_value)
{
   write_to_error_log("Warning! Variable X had a bad value!"); 
}

What’s the easiest way to do this, and is there a way to have it show up along with usual EE template errors (since it really would be a template error, despite being PHP)?

[Mod Edit: Moved to the Development and Programming forum]

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

There is:

$this->EE->TMPL->log_item('what you are loggin');

That will print to the template debugging log.

       
Michael C. (ProImage)'s avatar
Michael C. (ProImage)
102 posts
15 years ago
Michael C. (ProImage)'s avatar Michael C. (ProImage)

Perfect, thanks! Do I need…

global $TMPL;

…or is that automatic since I’m in a template already?

       
the3mus1can's avatar
the3mus1can
426 posts
15 years ago
the3mus1can's avatar the3mus1can

in EE 1.7 it would be:

global $TMPL;
$TMPL->log_item('what you are loggin');
       
Michael C. (ProImage)'s avatar
Michael C. (ProImage)
102 posts
15 years ago
Michael C. (ProImage)'s avatar Michael C. (ProImage)
in EE 1.7 it would be:
global $TMPL;
$TMPL->log_item('what you are loggin');

Ahh, thanks - that solved the problem I’d been having. 😊

       
chrcollins's avatar
chrcollins
77 posts
14 years ago
chrcollins's avatar chrcollins

I have the same issue but I am trying to log from an extension I am writing for the SAFE Cracker hook “safecracker_submit_entry_end”. I use the log_item method but it throws the php error as described above.

$this->EE->TMPL->log_item("debug:email = ".$msg);

I tried to load the template library but get the same error. Any suggestions?

EE 2.1.1

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

How are you loading the template library? Can you post a code snippet?

       
chrcollins's avatar
chrcollins
77 posts
14 years ago
chrcollins's avatar chrcollins
$this->EE->load->model('template_model');

I also tried the following as it seems more obvious …

$this->EE->template_model->log_item("exp:exhibit:debug:email = ".$msg);

.. with the same result.

Thanks!

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Try this:

$this->EE->load->library('Template', null, 'TMPL');
$this->EE->TMPL->log_item("exp:exhibit:debug:email = ".$msg);
       
chrcollins's avatar
chrcollins
77 posts
14 years ago
chrcollins's avatar chrcollins

Looks like that is working. I should have figured this out. Clearly the model does not have the log_item function. It is the library that has it. Also answers my question where those symbols are coming from like TMPL and DB, etc. Are they only local to the function / class that creates them our are they global in scope? Thanks!

Thanks for your help!

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

They are global.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.