Tuesday, January 29, 2013

Re: Using variable from controller in model

Are you sure that User->data exists after calling read()?

After calling set() debug the User->data to see whether id is set.

On Tue, Jan 29, 2013 at 9:41 AM, MetZ <metz80@gmail.com> wrote:
> Hi all.
>
> I am struggling passing a variable to my before save function in my User
> model.
>
> Controller:
> $this->User->read(null, $data['user_id']);
> $this->User->set(array(
> 'noslug' => 1,
> 'TEST' => 'sdfsd'
> ));
> $this->User->save();
>
> Model:
>
> if(empty($this->data[$this->alias]['noslug']) {
> // noslug empty, do somthing cool
> } else {
> // noslug not empty, do something else
> }
>
>
> $this->data[$this->alias]['noslug'] = always empty/false
>
> How can I read the "noslug" = 1 in my model?
>
> Thanks for any help on this!
> -Tom
>
> --
> 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.
>
>

--
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: