Blog

New in symfony 1.2: Small things matter (3)

Symfony Live 2010 Paris Conference

« Back to the Blog

Categories

Feeds

feed Posts feed

comments feed Comments feed

symfony training
Be trained by symfony experts
Feb 15: Paris (What's new in 1.3 / 1.4 - English)
Feb 15: Paris (and Zend Framework Together - English)
Feb 15: Paris (Hosting Practices with symfony - English)
Feb 24: Paris (1.4 + Doctrine - Français)
Mar 04: Online (What's new in 1.3/1.4 - Français)
and more...

Archives

Creative Commons License This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

Here comes the third edition of small things that might make you happy in symfony 1.2.

Tests coverage

When you test your code with unit or functional tests, it's quite handy to know if some code has not been covered.

As of symfony 1.2, the test:coverage task outputs the code coverage for some given tests:

./symfony test:coverage test/unit/model/ArticleTest.php lib/model/Article.php
 

The first argument is a test file or a test directory. The second one is the file or directory for which you want to know the code coverage.

If you want to know which lines are not covered, simply add the --detailed option:

./symfony test:coverage --detailed test/unit/model/ArticleTest.php lib/model/Article.php
 

Code coverage

Events

The event system introduced in symfony 1.1 makes the framework quite flexible. As new needs arise, new events are added:

You can read the web debug toolbar post to learn more about the new debug.* events.

Forms

The form framework is made better by the addition of several methods that simplifies its usage in the templates:

The renderUsing() method renders the form using a specific formatter:

// in a template, the form will be rendered using the "list" form formatter 
<?php echo $form->renderUsing('list') ?>
 

The renderHiddenFields() method returns the HTML needed to display the hidden widgets:

<form action="<?php echo url_for('@some_route') ?>">
  <?php echo $form->renderHiddenFields() ?>
  <ul>
    <?php echo $form['name']->renderRow() ?>
  </ul>
  <input type="submit" />
</form>
 

sfForm now also implements the Iterator interface:

<ul>
  <?php foreach ($form as $field): ?>
    <li><?php echo $field ?></li>
  <?php endforeach; ?>
</ul>
 

That's all for today.

Comments comments feed

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.