Wednesday, October 14, 2015

Pass a variable to a model construct

My experience of this is only with Cake 2, so I don't know if it is possible in Cake 3, but if it is, please point me in the right direction.

I find myself writing model files which pass the same parameters to my methods!

For example

My "Settings" model might have:

public function getSetting($id) {

}

public function updateSetting($id, $data) {

}

Rather than pass the $id each time I call a method, it would be great to pass this once when I declare the setting, for example:

$Setting = new $this->Setting($id);

And then to call my methods, use:

$Setting->updateSetting($data);

Is doing something like this possible in either CakePHP 2 or 3.

Thanks

--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: