我有一個前端控制器工作。我寫了一個名爲AuthController.php的登錄控制器。它內部配置了相應的代碼。我的問題是當我去/ auth我得到一個404。這似乎是某種路由問題。Zend新手問題與控制器
我的身份驗證控制器被稱爲AuthController.php和它的頂部是這樣的:下面
class AuthController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$form = new Application_Form_Login();
$request = $this->getRequest();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
if ($this->_process($form->getValues())) {
// We're authenticated! Redirect to the home page
$this->_helper->redirector('index', 'index');
}
}
}
$this->view->form = $form;
}
,當然也有保護功能,用於處理其他事情。在Zend中,當你創建一個新的控制器時,不僅僅它的存在(就像在CodeIgniter中那樣)意味着它應該可用?或者我必須將其添加到某個路由表中?
編輯:這是我的Apache虛擬主機配置:
<VirtualHost *:80>
ServerName new.mydomain.com
DocumentRoot /www/htdocs/zend/public
<Directory /www/htdocs/zend/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
有'[/ module]/controller/action'的默認路由如果你沒有指定動作,那麼它會嘗試執行'indexAction'。很難告訴你爲什麼它不能通過提供的代碼工作。如果404不是一個例外,而是服務器404的響應,那麼你的'mod_rewrite' /'htaccess'沒有正確配置。 –
我檢查了.htaccess,它看起來不錯。也許apache配置不正確。這不在我的服務器上,所以我會檢查。謝謝! –
你使用的是Apache嗎?你應該看看你的虛擬主機配置。如果設置不正確,您將只會顯示默認索引頁面,因爲Apache不會將路由傳遞給Zend。如果可以,請共享虛擬主機配置。 –