Hey everyone. If this has been answered before, I didn't find it on the
forums. Please link me if it was.
I'm a newbie with Cake. I've gone through and understand the MVC setup and
how it works. However, before I spend another countless hours I was
wondering if someone could point me into the right direction or provide
examples.
I'm using the newest release of CakePHP (2.3).
I have a site with a registration page at domain.com/register.
> Router::connect('/register', array('controller' => 'students', 'action' =>
> 'index'));
This page has a simple form with
echo $this->Form->create('Student', array('action' => 'register'));
> echo $this->Form->input('Full Name');
> echo $this->Form->input('Email');
> echo $this->Form->input('Password');
> echo $this->Form->end('Register');
> ?>
*I then have StudentsController :*
function index() {
> $this->set('title_for_layout', 'Register');
> $this->layout = 'students';
> $this->Student->recursive = 0;
> $this->set('students', $this->paginate());
> }
function register() {
> if ($this->request->is('post')) {
> $this->Student->create();
> if ($this->Student->save($this->request->data)) {
> $this->Session->setFlash(__('The user has been saved'));
> $this->redirect(array('action' => 'index'));
> } else {
> $this->Session->setFlash(__('The user could not be saved. Please, try
> again.'));
> }
> }
> }
*and Student (model) :*
App::uses('AuthComponent', 'Controller/Component');
>
> class Student extends AppModel {
> public $primaryKey = 'id';
> public $validate = array(
>
> 'full_name' => array(
> 'rule' => 'alphaNumeric',
> 'message' => 'We need your name!',
> 'required' => true
> ),
> 'email' => array(
> 'rule' => 'email',
> 'message' => 'A valid email is required',
> 'required' => true
> ),
> 'password' => array(
> 'password_one' => array(
> 'rule' => array('minLength', '8'),
> 'message' => 'Password is required (duh). Minimum of 8
> characters.',
> 'required' => true
>
> )
>
>
> ); //END VALIDATE
>
> }
>
>
>
It's still messy too so ignore any errors (which don't affect what I'm
trying to achieve) please. If I post the form, I get sent to /users/login.
I'd like to be sent to /students/register since my router does it to
/students/index. Then under register I want to handle all of the adding the
user stuff (see "function register() {" in the code above).
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. 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.
Thank you in advance!
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.