SUBSCRIBE VIA RSS


Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.

Topics

Stack Overflow


The old fashioned way

RECENT TUNES

  PHP Articles

June 12, 2007 – 4:12pm Symfony exceptions, logging, and debugging

Since I always forget, here is a quick reference for throwing exceptions and adding log/debug messages throughout your symfony project.

Exceptions
This is how you can throw a new symfony exception.

throw new sfException('An error occurred. Please go back and try again.');

Logging

Within an action, this is how you can log a message:

<?php use_helper('Debug') ?>
<?php if ($problem): ?>
  <?php echo log_message('{mainActions} been there', 'err') ?>
<?php endif ?>

And elsewhere within the code (model, etc):

sfContext::getInstance()->getLogger()->info($message);
sfContext::getInstance()->getLogger()->err($message);

Debugging

// in an action
$this->debugMessage($message);
// in a template
<?php echo debug_message($message) ?>

Reference: Symfony Docs: Debugging

Posted by in  Web Development   |     |  4 Comments »

June 10, 2007 – 11:53pm Turn off php magic_quotes_gpc within .htaccess or php.ini

A lot of shared hosts will have magic quotes turned on by default. This can create some extra overhead depending on your application. Symfony apps prefer to have this turned off. Here’s how you can do it using either an .htaccess or php.ini file in your web root directory.

#.htaccess
php_flag magic_quotes_gpc off
 
# php.ini
magic_quotes_gpc=off
</code>
Posted by in  Web Development   |     |  2 Comments »

May 26, 2007 – 2:59am Count your SLOC: Source Lines of Code

Although this number may mean nothing at all, counting the total number of Source Lines of Code (SLOC) can be fun. Here is how you can tally up all the lines of PHP you have in a project from the command line:

find . -regex '.*\.\(php\)' -print0 | xargs -0 cat | wc -l

You can read more about this on wikipedia.

Posted by in  Web Development   |     |  1 Comment »