我想在CakePHP中实现自定义路由。我正在关注文档
http://book.cakephp.org/2.0/en/development/routing.html#custom-route-classes
app/Routing/Route
<?php
App::uses('CakeRoute', 'lib/Cake/Routing/Route');
class CategoryRoute extends CakeRoute
{
public function parse($url)
{
$params = parent::parse($url);
if (empty($params)) {
return false;
}
return true;
}
}
app/Config/routes.php
App::uses('CategoryRoute', 'Routing/Route');
Router::connect('/mypage/*', array('controller' => 'mycontroller', 'action' => 'view'), ['routeClass' => 'CategoryRoute']);
但我得到
Missing Controller
Error: Controller could not be found.
Error: Create the class Controller below in file: app/Controller/Controller.php
当我删除['routeClass' => 'CategoryRoute']
时,重新路由工作正常。
答案 0 :(得分:1)
仔细查看API文档: API > CakeRoute::parse()
parse()
方法应该在成功时返回一个已解析参数的数组(即$params
),或者在失败时返回false
。