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