2012-11-08 69 views
0

我需要將路線添加到Zend Framwork Application。Zend Framework添加路線

我要顯示所有的數據庫中的帖子,其中產品類別=控制器名

domain.com/action 
domian.com/drama 
domain.com/thriller 

我怎樣才能做到這一點?我瀏覽了ZF Routes文檔。但沒有找到解決方案。

回答

1

爲了能夠做到這一點,你必須把這樣的事情在你的application.ini

resources.router.routes.category.type = "Zend_Controller_Router_Route" 
resources.router.routes.category.route = ":category" 
resources.router.routes.category.defaults.module = "default" 
resources.router.routes.category.defaults.controller = "index" 
resources.router.routes.category.defaults.action = "index" 

這樣,不匹配爲有效的控制器都將被引導爲類別參數在索引控制器索引操作中。請記住,處理無效的類別名稱並引發404

而且,這裏是一個很好的文章使用addRoute()方法中的bootstrap.php文件

// Retrieve the front controller from the bootstrap registry 
$FrontController = $this->getResource('FrontController'); 
$router = $FrontController->getRouter(); 

$router->addRoute('genre', 
        new Zend_Controller_Router_Route(
     ':genre',array('controller' => 'index' , 'action' => 'index' ))); 

tricks and tips in application.ini

0

這是可以做到獲得控制器中的流派

echo $this->getRequest()->getParam('genre')