Thanks again!
On Thursday, April 4, 2013 8:03:07 PM UTC-4, cricket wrote:
--On Sat, Mar 30, 2013 at 6:14 PM, Nathan Pierce <helius...@gmail.com> wrote:
If I post the form, I get sent to /users/login.You need to tell Auth that this action doesn't require login. Create a beforeFilter in StudentsController:function beforeFilter() {parent::beforeFilter();$this->Auth->allow('register'); }Add any other public actions. You can pass any number of strings as params, or an array of strings.What I'm trying to do is have the form register a user to the students table in my database. I will have to have another form on the site to register teachers and I want to keep them in separate databases.Do you mean separate tables? Or databases?Problem is, all of the auth stuff is sent to UserController, which I don't want to use. I want to pass all Student login form stuff to the StudentController and all Teacher to the TeacherController.
In short, how do I achieve this? How do I force cakephp to use something other than the UserController to handle everything? If you need further clarification, please ask.You can tell Auth what its "user model" should be:You would then include the AuthComponent in both the controllers, and NOT the AppController.However, I have no idea how/if this would work for your other controllers -- those which both Students and Teachers would be accessing. I wouldn't be surprised if Cake could handle it, but neither would I be optimistic. I suggest saving yourself a lot of pain by creating a User model through which everyone is authenticated and which both Students and Teachers extend. Have a look online for multi-table inheritance in Cake. Or you could even do it without inheritance:CREATE TABLE users (id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,created DATETIME DEFAULT NULL,modified DATETIME DEFAULT NULL,email VARCHAR(64) NULL,password CHARACTER(40) NULL,model VARCHAR(24) NOT NULL,foreign_key INT(10) UNSIGNED NOT NULL,...class User extends AppModel{public $hasOne = array('Teacher' => array('className' => 'Teacher','foreignKey' => 'user_id','dependent' => true),'Student' => array('className' => 'Student','foreignKey' => 'user_id','dependent' => true));// ...}class Teacher extends AppModel{public $belongsTo = array('User' => array());// ...}Just allow NULL in teachers & students user_id column, save the record, then create the User, then save the user_id. Upon login, check $this->Auth->user('model') and do $model = $this->User->{$model_name}->find(...) -- passing in $this->Auth->user('foreign_ key') -- and save that to the session.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment