On Wed, Apr 6, 2011 at 11:24 AM, Krissy Masters <[email protected]> wrote: > For a while I have been wondering and just never asked so here it goes. > > In the cookbook you see "$this->data" > example set($this->data) if(!$this->data) save($this->data) so on you get > the idea > > Online people write examples and its changed to $data > > Save($data), set('data', $data) so on > and curious if there is a difference, which is correct does it make a > difference? > > $this->data vs $data ? > > Is $this->data the correct "data" holder for cake and should be use or its > simply personal preference?
Funny, I had just mentioned something similar here: http://groups.google.com/group/cake-php/browse_thread/thread/1f04c99bf2a6c576?pli=1 You should be using $this->data if you're working with POSTed values in the controller. Cake automatically grabs that and puts it into the controller's $data class var. Thus, you refer to it as $this->data. When you do $this->Model->set($this->data) the Model's $data class var is set. Thus, it can now be referred to in the model as $this->data. If you read from the DB in the controller like this: $this->data = $this->Model->read(null, $id); ... then the View's class var $data will be set. Thus, it can be referred to in the view as $this->data. The bottom line is that you should always use $this->data unless you know otherwise. That is, don't follow my advice in the link above unless you're comfortable with what $this->data refers to. -- 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 [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
