2

I'm writing in symfony and I'm in one of the actions.class.php files.

Normally I would just echo the variable's value but because this is an actions class module, I can't do that because I can't output to the page.

I was thinking of using FirePHP but it involves installing it server-side and I'd like to be aware of an easier or built-in solution.

6
  • Is it possible to echo the variable and then after it use exit? Commented Feb 28, 2013 at 22:32
  • It seems to just cause the page to be blank. Commented Feb 28, 2013 at 22:34
  • 2
    dirty, messy, but emailing yourself would work. Commented Feb 28, 2013 at 22:34
  • @SchautDollar: Hah.. Yeah that might work. Commented Feb 28, 2013 at 22:34
  • @SchautDollar: Actually, emailing myself works really well. One line of code and it sends it rather instantly. Commented Feb 28, 2013 at 22:37

3 Answers 3

2

Emailing logs works for sure but there are some better, easier and faster ways to do that ;)

In symfony you have access to the Logger which will allow you to log anything. In prod environment by default it is disabled (of course you can switch it on) but in dev it's not only available in the log files but also prints in the Sf Web debug bar.

Inside an action use:

$this->getLogger()->debug('My $variable value is now: '.$variable);

You can also use other levels of logging (->warning(''), ->err(''), ->crit(''), etc.). Of course you need to change the variable to string if it is an array or an object.

In fact you can echo and var_dump things while in the action. They will show in your page (though mess badly with the layout as you're displaying stuff before the actual template).

Remeber that echo works only with strings and numbers. If you try to echo a boolean or array you will see nothing. If you try echo an object it's __toString() method will be used or an error raised.

Sign up to request clarification or add additional context in comments.

1 Comment

You should mention that it depends on the logging configuration of the environement (prod/dev/cache/etc ...). Sometimes, logging (even err or crit) aren't allowed on prod env.
1

Email yourself throughout the code. You could either send one at the end of the script or throughout. There are benefits to both. Emailing throughout will easily let you know where something went wrong if you don't get an email and emailing at the end save overhead(doesn't seem like it would be a problem here though).

Comments

1

If you have access to the server's log files, you might want to look into PHP's error_log function. It will print a string into PHP's error log and then you can check the log file.

-edit-: error_log also allows you to email yourself the message. But that's silly.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.