Cakephp Router::parseExtensions()仅用于特定路由
是否可以将Router::parseExtensions()仅用于一条路由Cakephp Router::parseExtensions()仅用于特定路由,cakephp,Cakephp,是否可以将Router::parseExtensions()仅用于一条路由 我只需要为我的SitemapsController使用xml扩展,而不需要其他路由。使用Router::parseExtensions(array('xml'))还提供不需要的/news/foo.xml,它等于/news/foo(重复内容)。如果您需要这样的请求 http://localhost/sitemap.xml 然后添加路线: Router::connect('/sitemap.xml', array('con
我只需要为我的
SitemapsController
使用xml
扩展,而不需要其他路由。使用Router::parseExtensions(array('xml'))
还提供不需要的/news/foo.xml
,它等于/news/foo
(重复内容)。如果您需要这样的请求
http://localhost/sitemap.xml
然后添加路线:
Router::connect('/sitemap.xml', array('controller' => 'sitemaps', 'action' => 'index'));
将beforeFilter()函数添加到SitemapsController.php:
public function beforeFilter() {
$this->viewClass = 'Xml';
}
如果您不想在路由规则中设置扩展,并且想要更复杂的解决方案,则必须设置正确的操作:
public function beforeFilter() {
$this->viewClass = 'Xml';
$action = reset(explode(".", $this->request->params['action']));
$this->setAction($action);
}
如果你需要这样的要求
http://localhost/sitemap.xml
然后添加路线:
Router::connect('/sitemap.xml', array('controller' => 'sitemaps', 'action' => 'index'));
将beforeFilter()函数添加到SitemapsController.php:
public function beforeFilter() {
$this->viewClass = 'Xml';
}
如果您不想在路由规则中设置扩展,并且想要更复杂的解决方案,则必须设置正确的操作:
public function beforeFilter() {
$this->viewClass = 'Xml';
$action = reset(explode(".", $this->request->params['action']));
$this->setAction($action);
}