JavaScript
x
public function loginAction(){
if($_POST){
$data = $this->getRequest()->getPost();
$adapter = $this->Authorization($data);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
}
}
When I submit POST I get Fatal error:
JavaScript
*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*
I try to disable layout with:
JavaScript
$this->_helper->layout()->disableLayout();
But also get same Fatal error.
I get an error in this line :
JavaScript
$result = $auth->authenticate($adapter);
Where can be problem in my aplication ?
Advertisement
Answer
I think the error comes from the adapter
you’re using. If you’re athenticating the user via a database table, I suggest you to use this code insatead :
JavaScript
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);
}
}
You could also see this post or you may refer to the Database Table Authentication doc.