Symfony 1.2 already comes with a lot of great new features but smaller things also matter a lot. Here is yet another post about small things we have recently added to symfony 1.2.

Action

In an action, you can now generate a URL by using the routing object directly thanks to the new generateUrl() proxy method:

public function executeIndex()
{
  $this->redirect($this->generateUrl('homepage'));
}
 

The generateUrl() method takes a route name, an array of parameters, and whether to generate an absolute URL as its constructor arguments.

Forms

We have added two new methods to sfForm that ease form handling in the templates.

The first one, hasErrors() returns true if the form has some errors and false otherwise. This method also returns false if the form is not bound. It is quite useful in a template when you want to display a message when a form has some errors:

<?php if ($form->hasErrors()): ?>
  The form has some errors you need to fix.
<?php endif; ?>
 

The second one, renderFormTag() generates the opening form tag for the current form. It also adds the enctype attribute if the form needs to be multipart and adds a hidden tag if the form method is not GET or POST:

<?php echo $form->renderFormTag(url_for('@article_update'), array('method' => 'PUT')) ?>
 

When a form is tied to a Propel object, the renderFormTag() method automatically changes the HTTP method based on the related object: it changes the method to POST for new objects, and to PUT for existing objects.

Propel tasks

The Propel tasks relying on Phing now output clears error messages if the embed Phing task fails.

propel error message

To ease the debugging, the propel:build-model, propel:build-all, and propel:build-all-load tasks also do not remove the generated XML schemas anymore if you pass the --trace option.

The propel:insert-sql task removes all the data from the database before re-creating all the tables. As it destroys information, it now asks the user to confirm the execution of the task. The same goes for the propel:build-all and propel:build-all-load tasks, as they call the propel:insert-sql task.

propel task confirmation

If you want to use these tasks in a batch and want to avoid the confirmation, pass the --no-confirmation option:

$ php symfony propel:insert-sql --no-confirmation

As for every release, symfony simplifies the developer life by providing more shortcuts and nicer error messages.

Published in #Living on the edge