Categories
symfony

A note on routing

Well, while I’ve been writing the plugins for symfony I noticed that using of predefined routes (with aliases) is really good to use.
As far as I could figured out from sfGuardPlugin routing via php code (not via yml) can be done the following way:

if (sfConfig::get(‘app_sfGuardPluginPlus_routes_register’, true)
and in_array(‘sfGuardAuthPlus’, sfConfig::get(‘sf_enabled_modules’)))
{
$r = sfRouting::getInstance();

// preprend our routes
$r->prependRoute(‘sf_guard_signup’, ‘/signup’, array(‘module’ => ‘sfGuardAuthPlus’, ‘action’ => ‘signup’));
$r->prependRoute(‘sf_guard_create’, ‘/create’, array(‘module’ => ‘sfGuardAuthPlus’, ‘action’ => ‘create’));
$r->prependRoute(‘sf_guard_password_request’, ‘/request_password’, array(‘module’ => ‘sfGuardAuthPlus’, ‘action’ => ‘password’));
}

It’s ok and I adjusted this code for my own purposes. But how to be if I’d like add a bit more complicated rules with additional parameters passed, and control passed data validity? It’s not complicated at all but it’s also not so clear. After some investigations here is what I figured out:

$r->prependRoute(‘sf_guard_confirm’, ‘/confirm/:id’, array(‘module’ => ‘sfGuardAuthPlus’, ‘action’ => ‘confirm’), array(‘id’ => ‘\w+’));

which obsiously means that id stuff should be passed with only alphanumeric chars.

And I refer you to more details on routing stuff here:

http://www.symfony-project.com/book/trunk/09-Links-and-the-Routing-System

Also could be worth to investigate a code for symony’s sfRouting class. I bet you may find there all the answers for all the questions 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *