public function loginAction(){
if($_POST){
$data = $this->getRequest()->getPost();
$adapter = $this->Authorization($data);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
}
}
当我提交POST时,我收到致命错误:
*Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message
'Method "init" does not exist and was not trapped in __call()' in
/home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Controller/Action.php:486
Stack trace:
#0 /home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Controller/Action.php(133): Zend_Controller_Action->__call('init', Array)
#1 /home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Controller/Action.php(133): ErrorController->init()
#2 /home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Controller/Dispatcher/Standard.php(281): Zend_Controller_Action->__construct(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http), Array)
#3 /home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#4 /home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Application/Boot in /home/pigusaku/domains/xxx.lt/public_html/my/library/Zend/Controller/Plugin/Broker.php on line 336*
我尝试使用以下命令禁用布局:
$this->_helper->layout()->disableLayout();
但也会得到相同的致命错误。
我在这行中收到错误:
$result = $auth->authenticate($adapter);
我的申请中可能存在哪些问题?
答案 0 :(得分:0)
我认为错误来自您adapter
您正在使用的错误。如果您通过数据库表验证用户身份,我建议您使用此代码insatead:
public function loginAction(){
if($_POST){
$data = $this->getRequest()->getPost();
$username = $data['username']; //<----get here the username field
$password = $data['password']; //<----get here the password field
$authAdapter = new Zend_Auth_Adapter_DbTable(
Zend_Db_Table::getDefaultAdapter(),
'users', //users table name, or by setTableName('users')
'username', // the username column, or by setIdentityColumn('username')
'password' // password column, or by setCredentialColumn('password')
);
$authAdapter->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
}
}
您还可以看到此post,或者您可以参考Database Table Authentication doc。
希望这会有所帮助。