2011-06-28 86 views
1

我正在用Zend Server在Zend MVC中創建一個Hello World項目。一些路由是錯誤的。我創建項目通過zend_tool zf.sh創建項目,因此它創建的所有目錄本身,我修改爲indexController的嘗試像下面的一些行動,和所有其他文件提醒一樣..zend框架簡單的動作問題

<?php 

class IndexController extends Zend_Controller_Action 
{ 

    public function init() 
    { 
     /* Initialize action controller here */ 
    $this->_helper->viewRenderer->setNoRender(); 
    } 

    public function indexAction() 
    { 
     // action body 
    $this->getResponse()->appendBody('hello from about Action'); 
    } 

    public function aboutAction() 
    { 
    $this->getResponse()->appendBody('hello from about Action'); 
     // action body 
    } 


} 


當我輸入「http://localhost/index.php」,它顯示來自indexAction()的正確信息;
當我輸入「http:// localhost/index」,它顯示頁面沒有找到
當我輸入「http://localhost/index.php/about」,
它顯示「消息:無效的控制器指定(約)「 請求參數:

陣列( '控制器'=> '約',
'動作'=> '索引', '模塊'=> '默認', )

我期望控制器是索引和行動是關於..我怎麼能修復它...

我有這在我的apache配置。我想我可能有這個配置錯誤,但我不知道在哪裏。

<VirtualHost *:80> 
#DocumentRoot "/usr/local/zend/apache2/htdocs" 
DocumentRoot /home/testuser/projects/helloworldproject/public 
<Directory "/home/testuser/projects/helloworldproject/public/"> 
    SetEnv APPLICATION_ENV "development" 
    Order allow,deny 
    Allow from All 
</Directory> 

感謝您的時間。

回答

0

我想這正是錯誤信息說的,這就是你需要一個控制器about,你沒有。在url http://localhost/index.php/about,about將是一個完全獨立的控制器,你需要建立。

+0

但我預計服務器解釋指數控制器的左右作用。 – Nissan911

+0

@ Nissan911我明白你爲什麼會這麼想。但是,Zend正在以上述格式尋找一個「about」控制器。 – Nic

1
  • localhost/index.php應該去index控制器,默認情況下(index, index)index行動。
  • localhost/index也應該去(index,index)
  • index.php/about我希望去(about,index),即about控制器和index行動,但我可能是錯的(我沒有測試這一點)。
  • 如果你想去(index,about)你會去localhost/index/about

您似乎是正確定義的有關行動public function aboutAction,這樣應能正常工作。 如果您希望能夠轉到localhost/about或localhost/about/index,您需要像爲IndexController所做的那樣定義一個像class AboutController extends Zend_Controller_Action這樣的控制器。

- 編輯 - 此外,請確保您的.htaccess着眼於最低是這樣的:

DirectoryIndex index.php 

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ /index.php [NC,L] 
+0

正如我所說的。找不到localhost/index - >頁面。和localhost/index/about服務器解釋爲關於控制器,這完全不是我的意思.. – Nissan911

+0

@ Nissan911是你的.htaccess正確配置? – Nic

+0

你正在使用哪個Web服務器?如果Apache,你有你的.htaccess正確配置? – ashurexm