The Containable
behavior is a part of the CakePHP core, and is probably one of the most important behaviors we have to help us deal with model bindings.
Almost all CakePHP applications will benefit from its functionalities, so in this recipe we see how to enable it for all models.
Create a file named app_model.php
and place it in your app/
folder, with the following contents. If you already have one, make sure that either you add the actsAs
property shown as follows, or that your actsAs
property includes Containable
.
<?php class AppModel extends Model { public $actsAs = array('Containable'); } ?>
The Containable
behavior is nothing more and nothing less than a wrapper around the bindModel()
and unbindModel()
methods, defined in the CakePHP's Model
class. It is there to help us deal with the management of associations without having to go through a lengthy process of redefining all the associations when calling one of these...