Sunday, March 4, 2012

Re: linked models and save

now, user is saved ?

if it's still not, then is problem FOR user in validation, after call save() method for User, debug($this->Tutor->User->validationErrors);

i'm sure you failed with $this->request->data('PASSWORDTUTOR')
--
Lep pozdrav, Tilen Majerle



2012/3/4 Cédric Chabert <ced.chabert@gmail.com>
Thank you for this answer !

Actually there is validated beforeSave, and the password is hashed.

class User extends AppModel {
   public $name = 'User';

   public $hasOne = 'Tutor';

   public $validate = array(
       'username' => array(
           'required' => array(
               'rule' => array('notEmpty'),
               'message' => 'A username is required'
           )
       ),
       'password' => array(
           'required' => array(
               'rule' => array('notEmpty'),
               'message' => 'A password is required'
           )
       ),
       'role' => array(
           'valid' => array(
               'rule' => array('inList', array('student','tutor')),
               'message' => 'Please enter a valid role',
               'allowEmpty' => false
           )
       )
   );


public function beforeSave() {
   if (isset($this->data[$this->alias]['password'])) {
       $this->data[$this->alias]['password'] =
AuthComponent::password($this->data[$this->alias]['password']);
   }
   return true;
}
}

On Mar 4, 6:01 pm, Tilen Majerle <tilen.maje...@gmail.com> wrote:
> $dataUser should be something like this
>
> $dataUser = array('User' => array('username' => $this->request-
>
> >data('LOGINTUTOR'), 'password' => $this->request-
> >data('PASSWORDTUTOR'), 'role' => 'tutor'));
>
> and make sure that model is not validated before save, maybe here is
> problem too :)
> --
> Lep pozdrav, Tilen Majerlehttp://majerle.eu
>
> 2012/3/4 Cédric Chabert <ced.chab...@gmail.com>
>
>
>
>
>
>
>
> > $dataUser = array('username' => $this->request-
> > >data('LOGINTUTOR'), 'password' => $this->request-
> > >data('PASSWORDTUTOR'), 'role' => 'tutor');

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: