I worked this one out. I had the beforesave within the accounts model
while it should have been in the users model seeing that is where the
data was being saved.

Easy really but as I only just started cakephp there are many things
like this I am yet to understand.

Thanks



On Jul 7, 3:36 pm, elogic <asymo...@elogicmedia.com.au> wrote:
> Hi All,
>
> I am having some issues with the following: I have 2 tables that I
> have saving data to, accounts and users. I need to save the password
> field within users as MD5 and so I am usingbeforesavefunction in my
> model. It seems to be ignoring it though. Any ideas how I can go about
> this?
>
> ACCOUNT model
> ----------------------------------------------------------------
> functionbeforeSave() {
>    if ($this->data['User'][0]['password'])
>    {
>                 $this->data['User'][0]['password'] = 
> md5($this->data['User'][0]
> ['password']);
>                 echo $this->data['User'][0]['password'];
>    }
>    return true;}
>
> -----------------------------------------------
>
> NOTE: Above I have echo $this->data['User'][0]['password'], this is
> printing out the encrypted password...
>
> ACCOUNT controller
> ------------------------------------------------------------------
>
>         function edit($id = null) {
>                 if (!$id && empty($this->data)) {
>                         $this->Session->setFlash(__('Invalid account', true));
>                         $this->redirect(array('action' => 'index'));
>                 }
>                 if (!empty($this->data))
>                 {
>                         if ($this->Account->save($this->data))
>                         {
>                                 $this->data['User'][0]['account_id'] = 
> $this->Account->id;
>                                 $this->Account->User->save($this->data);
>
>                                 $this->Session->setFlash(__('The account has 
> been saved', true));
>                                 echo "<pre>";
>                                 print_r($this->data);
>                                 echo "</pre>";
>                                 //$this->redirect(array('action' => 'index'));
>                         } else {
>                                 $this->Session->setFlash(__('The account 
> could not be saved.
> Please, try again.', true));
>                         }
>                 }
>                 if (empty($this->data)) {
>                         $this->data = $this->Account->read(null, $id);
>                 }
>                 //$users = $this->Account->User->find('list');
>                 //$this->set(compact('users'));
>         }
> ----------------------------------------------------------------
> NOTE: by this stage the password is back to the unencrypted way...
> (when I call the print_r($this->data);)
>
> Thanks

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

Reply via email to