routes - 使用可选参数配置 Silex 路由

标签 routes silex

我已经配置了这2条路由

$app->match ( '/controller/param/{country}/{q}', "demo.controller:demoAction" )->value ( 'country', 'de' )->value('q', '')->bind ( 'demo_action_with_country' );
$app->match ( '/controller/param/{q}', "demo.controller:demoAction" )->value ( 'q', '' )->bind ( 'demo_action_without_country' );

但是 - 这不起作用。如果我调用 /controller/param/Test-String 路由匹配并返回内容。如果我调用 /controller/param/DE/Test-String 我得到 NotFoundHttpException

我该如何解决这个问题?

最佳答案

好的,我可以自己轻松解决这个问题。这是我的解决方案:

$app->match ( '/controller/param/{q}', "demo.controller:demoAction" )->value ( 'q', false )->bind ( 'demo_action_without_country' );
$app->match ( '/controller/param/{country}/{q}', "demo.controller:demoAction" )->value ( 'country', false )->value('q', '')->bind ( 'demo_action_with_country' );

关于routes - 使用可选参数配置 Silex 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17881459/

相关文章:

ruby-on-rails - 摆脱 Rails 中包罗万象的路线的技术

routes - Play Framework 。路线。错误: "not enough arguments for method at..."

php - Silex 微框架和 Twig : enable debug

php - 将库添加到 silex

javascript - 将 VueJS 与 Rails 现有应用程序部分集成

Laravel 允许用户在满足条件时访问特定路由

c# - 如何在 ASP.NET MVC 中为我的管理部分设置路由?

php - Silex check_path 验证用户登录的代码

php - 在 Silex 中检测环境类型(生产、开发或暂存)

phpunit - Silex phpunit 不匹配路由