Hi. I would like to set default value for some variable. Sometimes, I'm overwriting its value with custom one, but sometimes I'm overwriting it with empty value. Then, I'm trying to go back to my first value. Sounds quite freaky, but sample code will show my point (hopefully) #application_controller:
function setDefaultFooValue(){ if(!$this->Foo){ $this->Foo = $this->Bar->find('all',array('limit'=>10); } }
#baz_controller
function doSomething(){ //do some stuff $this->Foo = $this->Bar->find('all',array('conditions'=>array('my freaky conditions goes here') ); }
and now, two possibilities: $this->Foo has some values (everything is ok) $this->Foo is empty (I would like to return to value from setDefaultFooValue() ) but how? I'm trying: #baz_controller: function __construct(){ $this->afterFilter('setDefaultFooValue'); } but it don't work. calling $this->setDefaultFooValue() in __destruct() function don't works too. So, is there any way to call some filter before view, but after controller method? Or maybe there is other solution?
Any hints will be greatly appreciated Sorry for my language errors - English isn't my native lang.
CommentAuthorbermi
Perhaps afterInstantiate will work for your scenario
public function afterInstantiate()
{
// set the defaults
return true;
}