|
For some reason the UsersController after login is not finding the User model.
// UsersController.php public function login() { if (!empty($this->request->data)) { if ($this->Auth->login()) { try { $this->User->loginMeta($this->request->data); return $this->redirect($this->Auth->redirect()); } catch (Exception $e) { $this->Session->setFlash($e->getMessage()); $this->Auth->logout(); } } else { $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth'); } } } /// Error Output Notice (8): Array to string conversion [CORE\Cake\Model\Datasource\DboSource.php, line 436] Notice how in that output it goes to AppModel::loginMeta() after the UsersController::login()? When my code clearly says : $this->User->loginMeta($this->request->data); which is a call to the UserModel. It should say UserModel::loginMeta() not AppModel::loginMeta(). BTW... I put some text in the User.php file that should throw a fatal error if the file is being loaded, and it does not throw the Fatal error. Instead it brings me back to the login page with this output in the flash message. SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'loginMeta' at
line 1
-- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
|
Have you do this ?
function beforeFilter() { $this->Auth->authenticate = array( 'Form' => array('userModel' => 'User') ); } On Oct 19, 1:21 pm, zuha <[hidden email]> wrote: > For some reason the UsersController after login is not finding the User > model. > > *// UsersController.php* > > public function login() { > if (!empty($this->request->data)) { > if ($this->Auth->login()) { > try { > $this->User->loginMeta($this->request->data); > return $this->redirect($this->Auth->redirect());} catch (Exception $e) { > > $this->Session->setFlash($e->getMessage()); > $this->Auth->logout();} > > } else { > $this->Session->setFlash(__('Username or password is incorrect'), > 'default', array(), 'auth'); > } > > } > } > > */// Error Output* > > *Notice* (8): Array to string conversion [*CORE\Cake\Model\Datasource\DboSource.php*, line *436*] > Code Context > > PDOStatement::execute() - [internal], line ?? > DboSource::_execute() - CORE\Cake\Model\Datasource\DboSource.php, line 436 > DboSource::execute() - CORE\Cake\Model\Datasource\DboSource.php, line 403 > DboSource::fetchAll() - CORE\Cake\Model\Datasource\DboSource.php, line 645 > DboSource::query() - CORE\Cake\Model\Datasource\DboSource.php, line 587 > Model::__call() - CORE\Cake\Model\Model.php, line 720 > AppModel::loginMeta() - APP\Plugin\Users\Controller\UsersController.php, line 48 > UsersController::login() - APP\Plugin\Users\Controller\UsersController.php, line 48 > ReflectionMethod::invokeArgs() - [internal], line ?? > Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 473 > Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 107 > Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 89 > [main] - APP\webroot\index.php, line 125 > > Notice how in that output it goes to AppModel::loginMeta() after the > UsersController::login()? When my code clearly says > : $this->User->loginMeta($this->request->data); which is a call to the > UserModel. It should say UserModel::loginMeta() not > AppModel::loginMeta(). > > BTW... I put some text in the User.php file that should throw a fatal error > if the file is being loaded, and it does not throw the Fatal error. > Instead it brings me back to the login page with this output in the flash > message. > > *SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error > in your SQL syntax; check the manual that corresponds to your MySQL server > version for the right syntax to use near 'loginMeta' at line 1* -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
|
In reply to this post by zuha-3
You have Users plugin. User model is not found and Cake creates an instance of AppModel.
(this odd behavior enables you to query db tables without having to create model first.) Make sure "class User extends UsersAppModel" and configure Auth to use "Users.User" as model name: $this->Auth->authenticate = array( 'Form' => array( 'userModel' => 'Users.User', 'fields' => array('username' => 'email', 'password' => 'password'), 'scope' => array('User.active' => 1) ) ); in AppController::beforeFilter() or elsewhere. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
|
Thank you, thank you, thank you. That worked nicely.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
|
Hey thanks,
I had the same problem which has been resolved by using this solution. -- View this message in context: http://cakephp.1045679.n5.nabble.com/Login-Difficulty-CakePHP-2-0-tp4916439p5708683.html Sent from the CakePHP mailing list archive at Nabble.com. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php |
| Powered by Nabble | Edit this page |
