Monday, December 28, 2009

Re: coding practices with models

If you want to instantiate a banana, you should write it like this,
$Banana =& ClassRegistry::init('Banana');

then you may now execute the peel() like this,
$Banana->peel($id);

On Dec 28, 10:14 am, Christian <cdamiani...@gmail.com> wrote:
> When i come across situations that I feel needs to be coded inside the
> model I'm not sure whether (form the perspective of the controller or
> a different model) to treat a model as an object, or just as a
> collection of class methods.
>
> For example:
>
> If I want to peel a banana..
>
> Is it correct to instantiate the Banana
> $this->Banana->read(null,$id);
>
> and then call the method
> $this->Banana->peel();
>
> and in banana.php:
> function peel() {
>    //since this method was called on a specific instance
>    //it should have access to it's private variables (tuple from the
> database)
>
> }
>
> OR do i just call the method on the id and sort that out in the model
>
> $this->Banana->peel($id);
>
> then...
> function peel($id) {
>    //need to instantiate the banana first before we can operate on it
>   $this->Banana->read(null,$id);
>
> }
>
> I'm curious about the practices of some of you regular cakers.
> thanks

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en

No comments: