It should work this way
$modelName = 'Setting';
$data = $this->$modelName->find('all');
no need to use {
}
curly braces
Question
I am using CakePHP 2. We can access a Model named 'Setting' as $this->Setting->find('all')
however, how could i make the 'Setting' value a Variable. Something like
$modelName = 'Setting';
$data = $this->{$modelName}->find('all');
Any help is appreciated!
Solution
It should work this way
$modelName = 'Setting';
$data = $this->$modelName->find('all');
no need to use {
}
curly braces
OTHER TIPS
I use to initiate my main model like this
$modelClass = $this->Mymodel;
And I use model functions like this
$modelClass->id = $id;
$modelClass->save($this->request->data);
$this->request->data = $modelClass->find('first',array('conditions'=>array('id'=>$id)));
I hope that will work for you