cal*_*die 8 routing symfony silex
我正在尝试使用Silex(它使用Symfony路由组件 - 做一些事情 - 因此答案可能也适用于Symfony)
我将Silex添加到遗留应用程序以提供路由,但我需要尊重现有应用程序默认实现以加载文件(这只是从文件系统加载文件形式指定的URL).
编辑:澄清:在进行一系列引导调用之后,现有文件作为父模板中的包含从文件系统加载.
我发现的是,在缺少与遗留页面匹配的已定义路由的情况下,Silex正在抛出异常.
我真的需要一种方法来提供处理这些遗留页面的默认(回退)机制 - 但我的模式必须匹配整个URL(而不仅仅是一个片段).
这可能吗?
// Include Silex for routing
require_once(CLASS_PATH . 'Silex/silex.phar');
// Init Silex
$app = new Silex\Application();
// route for new code
// matches for new restful interface (like /category/add/mynewcategory)
$app->match('/category/{action}/{name}/', function($action, $name){
//do RESTFUL things
});
// route for legacy code (If I leave this out then Silex
// throws an exception beacuse it hasn't matched any routes
$app->match('{match_the_entire_url_including_slashes}', function($match_the_entire_url_including_slashes){
//do legacy stuff
});
$app->run();
Run Code Online (Sandbox Code Playgroud)
这必须是一个常见的用例.我试图提供一种方法来与遗留代码一起使用RESTFUL接口(load /myfolder/mysubfolder/my_php_script.php)
cal*_*die 28
我在symfony食谱中找到了答案......
http://symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html
$app->match('{url}', function($url){
//do legacy stuff
})->assert('url', '.+');
Run Code Online (Sandbox Code Playgroud)