• Posted by Peter Haza
  • On May 13, 2008

  • Filed under PHP, Symfony

  • No Comments

Using lists instead of tables with sfGuardAuth

For some reason, symfony 1.1′s new sfForm class is using sfWidgetFormSchemaFormatterTable by default, instead of sfWidgetFormSchemaFormatterList. This means that you get a form based on tables, while I prefer to think of my form as a list to fill in. To change this you can use this chain:

$form->getWidgetSchema()->setFormFormatterName('list');

The question is, “where do you put this to alter sfGuard’s login form?”

In the case of sfGuard you just need to create a new folder under apps/frontend/modules/ (replace frontend with your app name) called sfGuardAuth, in this you create a folder called actions, and within this again a file called actions.class.php.

apps/
-frontend/
--modules/
---sfGuardAuth/
----actions/
-----actions.class.php

Inside the actions.class.php file you put this:

<?php
    require_once sfConfig::get('sf_plugins_dir').
    '/sfGuardDoctrinePlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php';

/**
* Extend to use list schema formatter
*/
class sfGuardAuthActions extends BasesfGuardAuthActions
{
    public function executeSignin($request)
    {
        parent::executeSignin($request);
        $this->form->getWidgetSchema()->setFormFormatterName('List');
    }
}
?>

We manually include BasesfGuardAuthActions.class.php because symfony’s black magic autoloader doesn’t pick this up. Voila. Nice and easy!

If you wanna make your completely own sfWidgetFormSchemaFormatter you can read about it over at notjosh’s blog.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

What do you think? Join the discussion...