Search code examples
symfonysilex

Assert in silex with defined options


Want to assert a function in Silex with some pre-defined slugs. My idea is to have this code, but to have the choice to add in the slug assert some different assertions as 'about-us', 'contact' and 'services'. Any idea?

$app->get('/{slug}', function ($slug) use ($app) {

[...]

})
->bind('page')
->assert('slug', 'about-us')
;

Solution

  • You can use regular expressions in the second argument of assert method. Add list of available slug values:

    ->assert('slug', 'about\-us|contact|services');