php - Silex dynamic routing call Class\Controller dynamically like Yii -


i'm not able find way use dynamic routing silex in way yii does.

for example yii in config.php has following routing definitions:

'<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 

so dynamically call controller based on url path. how it's possible in silex? i'm trying doesn't work:

$app->match('/{controller}/{action}', function($controller,$action) {   $controller = ucwords($controller);   $name = "def\controller\{$controller}controller::{$action}action";   return new $name; })->method('get'); 

it looks $name variable has problem because using single backslashes, escape character. also, avoid using {%variable} syntax. better concatenate string's elements (.) dot operator, less error-prone , code easier read way.

try:

$name = "def\\controller\\".$controller."controller::".$action."action"; 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -