CakePHP Cheatsheet
Posted on | November 26, 2008 | 2 Comments
This is one good stuff. Easy reference of CakePHP with this cheatsheet, produced by Cakephp. Not an up to date version, judging from the copyright line. But still helpful.
http://cakephp.org/files/cakesheet.pdf
Containable Behavior
Posted on | November 23, 2008 | No Comments
Cakephp Beta 1.2 RC has a new core behavior called Containable. This behavior is used to setup relationship between models. Instead of using bindable, I am now using the Containable behavior, which makes things easier.
You can leave the recursive = -1 out of your codes when using this behavior.
Get it working
Define $actAs variable in your model:
$actAs = array('Containable');
or on-the-fly
$this->Feature->Behaviors->attach('Containable');
Get your results
$this->paginate = array('contain' => array('Attachment.filename', 'User'),'limit' => 20, 'order' => array('Feature.created' => 'DESC'));
What this code does is filter only fields specified in “contains”, retrieves only 20 records “limit”, in order specified by “order”.
Replace $this->Feature->recursive = -1; by setting the contain to false
$this->paginate = array('contain' => false,'limit' => 20, 'order' => array('Feature.created' => 'DESC'));
Reuseable page elements with renderElement()
Posted on | November 18, 2008 | 2 Comments
When you find yourself repeating HTML codes in pages of your website or web application, this is a useful function for factoring your codes. Whenever I make changes to my codes, I will make it a point to refactorize as much as possible. It keeps the codes managable. But over factorizing will make it hard for the next programmer taking over the maintenance of the application.
renderElement() is just one of the ways to factorizing your codes. In Cakephp, you can make use of custom helpers, tempalates, plugins, components to make your code reuseable and tidy.




















