2009-08-13 116 views
3

我剛開始用zend framework 1.9.1進行冒險,但是我遇到了一些問題。我想刪除默認路由,從而避免顯示不同的URL相同的內容 - 才達到它,我在bootstraper寫自定義函數ZF路由問題

<?php 

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{ 
    protected function _initMyRouter() 
    { 
     $this->bootstrap('router') 
      ->getContainer() 
      ->frontcontroller 
      ->getRouter() 
      ->removeDefaultRoutes(); 
    } 
} 

但在此之後,一個問題出現 - 每一個無效的URL達到默認的控制器,而不是錯誤控制器。爲了解決這個問題,我把 resources.frontController.defaultcontrollername =「錯誤」 resources.frontController.defaultaction =「扔」在的application.ini 和

public function throwAction() 
{ 
    throw new Zend_Controller_Dispatcher_Exception; 
} 

在ErrorController要解決這一點,但我的問題是.. 。 難道我做錯了什麼?

第二個問題是我只需要生成絕對URL,因此我在application.ini中添加了resources.frontController.baseurl =「http://mydomain.com/」,但之後每個URL指向默認控制器。如何解決它?

第三個(也是最後一個)是......如何在我的操作中調用Zend_Controller_Action_Helper_Url :: url?我試過類似$ this - > _ helper-> url(array(),'frontpage'),但它調用Zend_Controller_Action_Helper_Url :: direct

回答

1

我會先回答第三個問題,因爲我可以告訴你我的頭頂。

我一般使用$this->view->url(array(...), 'routeName', true);最後一個參數重置參數。我發現視圖助手比Action Helper更容易/更快速的輸入。雖然我認爲$this->_helper->url->url(...)是到達行動幫手的正確途徑。

我從來沒有刪除默認路由 - 但如果當天晚些時候沒有任何其他答案 - 我會盡我所能在工作時間後爲您做一些測試。