On Jul 26, 9:37 pm, "R. Rajesh Jeba Anbiah"
<[EMAIL PROTECTED]> wrote:
<snip>
> Many thanks for your kind and quick reply. I think, my problem is
> due to beforeSave, afterSave, etc. So, I'm wondering if I can limit
> the those calls for a particular model methods. I'll look at that
> tomorrow (time here is 1am). Thanks again.
Hi Rajesh,
There isn't afaik a (un)bindBehavior method, and you can't otherwise
avoid the methods being called; but you can prevent the behavior from
doing anything.
If you write your behaviors like so:
class ABehavior extends ModelBehavior {
function setup(&$model, $config = array ()) {
$settings = am(
array (
// more default settings
'enabled' => true // enabled by default
),
$config
);
$this->settings[$model->name] = $settings;
}
function afterSave(&$model, $created) {
extract($this->settings[$model->name]);
if (!$enabled) {
return true;
}
// stuff
}
}
The question only becomes how to set $enabled to be true/false to get
what you want. At the moment what I do is have the following method in
the behavior:
function enable<BehaviorName> (&$model, $enable = null) {
if ($enable !== null) {
$this->settings[$model->name]['enabled'] = $enable;
}
return $this->settings[$model->name]['enabled'];
}
The name of the behavior is included in the method to avoid namespace
conflicts and make it possible to enabled/disable each behavior where
there are more than one.
It may be more versatile to create a method in the (app - for
now)model enableBehavior($behaviorName, $enable = null) which does the
same thing, or maybe even behaviorSettings($behaviorName,
$settingName=null, $settingValue=null)
Anyway, hth,
AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---