All*_*lly 2 php phalcon phalcon-routing
我现在正在抨击Phalcon,试图让我了解它,因为我正在考虑将一个大项目从CodeIgniter移植到Phalcon或其他框架,然后继续开发.
我正在使用路由器尝试捕获404错误,但这不能按预期工作.路由器它自己似乎正在工作,因为我还必须$router->add("/"获取站点索引控制器,如果index.php没有定义,如果我评论出来,回家/然后抛出404!但是,键入一些不存在的控制器名称,例如test,给出错误"PhalconException:TestController处理程序类无法加载".我的htaccess是根据Phalcon docs教程.
在bootstrap(index.php)中我有;
$di->set('router', function() {
require __DIR__ . '/../app/config/routes.php';
return $router;
});
而我的routes.php看起来像这样;
$router = new \Phalcon\Mvc\Router();
// default
$router->add("/", array(
'controller' => 'index',
'action' => 'index'
));
//Set 404 paths
$router->notFound(array(
"controller" => "group",
"action" => "index"
));
$router->handle();
return $router;
Run Code Online (Sandbox Code Playgroud)
该站点具有domain.com/group-name/到达的用户提交的组.在CI中,我使用404路由加载组控制器,该组控制器将激活对该组的搜索.如果找到它将显示该组,如果没有它将抛出404页面与404标题.很可能在Phalcon中有更好的方法,但我至少想知道为什么我的notFound溃败无法工作;)
编辑:不确定这是否会改变,但我使用的是基本控制器"controllerBase",所有主控制器都在扩展.它只包含一些变量和初始化函数以及可以从控制器调用的另一个函数.我不会想到这会影响notFound路由,但我想我最好提一下.
小智 6
\ Phalcon\Mvc\Router的默认行为不使用notFound()方法.
如果您想使用notFound(),则需要首先禁用默认路由,如下所述:http://docs.phalconphp.com/en/latest/reference/routing.html#default-behavior
在您的示例中,您只需要更改:
$router = new \Phalcon\Mvc\Router();
Run Code Online (Sandbox Code Playgroud)
以下内容:
$router = new \Phalcon\Mvc\Router(false);
Run Code Online (Sandbox Code Playgroud)