我的phalcon应用程序在标准MVC路由约定中工作得很好。但是,我想通过URL处理一些变量,然后我有一个路由:
$router = new \Phalcon\Mvc\Router();
$router->add("/timesheet/some/{year:[0-9]+}/{month:[0-9]{2}}/{day:[0-9]{2}}", "Timesheet::some");
$router->add("/timesheet/getreport/{type:[a-z]}/{year:[0-9]+}/{month:[0-9]{2}}/{day:[0-9]{2}}", "Timesheet::getreport");
$router->addPost("/user/auth", "User::auth");
return $router;$year = $this->dispatcher->getParam("year");访问“年份”、“月份”变量,但是第二条路径(时间表/getreport)不起作用。在本例中,$year = $this->dispatcher->getParam("year");返回null。每个请求都将被路由到索引/索引。我的项目URL是localhost/fpa,并且我已经尝试过路由/fpa /timesheet/some和/timesheet/some,但是它总是重定向到index/index。它有什么问题?(安全性/auth被注释掉,所以它不是身份验证的结果)。
非常感谢。
发布于 2014-11-03 22:21:43
它适用于我:
$router = new Phalcon\Mvc\Router();
$router->add("/", array(
'controller' => 'index',
'action' => 'setLanguage',
));
$router->add("/{language:[a-z]{2}}", array(
'controller' => 'index',
'action' => 'index',
'language' => 1
));这个get的默认路由在一开始就使用了语言
$router->add("/{language:[a-z]{2}}/:controller/:action", array(
'controller' => 2,
'action' => 3,
'language' => 1
));在未在url中时,使用默认操作"index“
$router->add("/{language:[a-z]{2}}/:controller", array(
'controller' => 2,
'action' => 'index',
'language' => 1
));其他一些路线
$router->add("/{language:[a-z]{2}}/:controller/:action/:params", array(
'controller' => 2,
'action' => 3,
'language' => 1,
'params' => 4
));
$router->add("/{language:[a-z]{2}}/question/add/{type}", array(
'language' => 1,
'controller' => 'question',
'action' => 'add',
));https://stackoverflow.com/questions/26698271
复制相似问题