我想有我的網址是這樣的:漂亮Zend框架的URL
/index
/contact
/articles
/articles/selection
- ...
代替:
/index/index
/index/contact
/articles/index
/articles/selection
- ...
基本上我只有一個控制器。哪種解決方案最適合執行此操作? (控制器和重定向,ZF路由,url重寫,別的東西?)
我想有我的網址是這樣的:漂亮Zend框架的URL
/index
/contact
/articles
/articles/selection
代替:
/index/index
/index/contact
/articles/index
/articles/selection
基本上我只有一個控制器。哪種解決方案最適合執行此操作? (控制器和重定向,ZF路由,url重寫,別的東西?)
看看文檔。你想要的行爲被配置爲默認的缺省路由器: http://framework.zend.com/manual/en/zend.controller.router.html
如果第一個參數不映射模塊名稱,它將搜索控制器如果失敗過,所以尋找一個動作你索引控制器。 您是否嘗試過打電話給您的網址? 如果您導航到/index
會發生什麼情況?應該是相同的像/index/index
使用Zend的路由:
$router = Zend_Controller_Front::getInstance()->getRouter();
$route_index = new Zend_Controller_Router_Route(':action', array(
'module' => 'default',
'controller' => 'index',
'action' => 'index'
));
$router->addRoute('route_index', $route_index);
$route_articles = new Zend_Controller_Router_Route('articles/:action', array(
'module' => 'default',
'controller' => 'articles',
'action' => 'index'
));
$router->addRoute('route_articles ', $route_articles);
如果他不覆蓋默認路由器,則不需要。 我想你的第二個url描述符應該是'/ articles /:action'。 – 2012-02-26 00:00:23
這是我的建議是什麼(見我的問題),但我想,以避免產生這種簡單的控制器(1個動作)如果可能的話:/ – 2012-02-26 11:28:09
所以你必須配置你的路由器,並設置類型參數,如 $ article_route = new Zend_Controller_Router_Route('/ articles /:type',array('module'=>'default','controller'=>'index', 'action'=>'article','type'=>'index')); 依此類推。 – 2012-02-26 11:54:57