Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp Router::parseExtensions()仅用于特定路由_Cakephp - Fatal编程技术网

Cakephp 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

是否可以将Router::parseExtensions()仅用于一条路由


我只需要为我的
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);
}