Reputation: 2728
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!
Upvotes: 0
Views: 1375
Reputation: 24344
It should work this way
$modelName = 'Setting';
$data = $this->$modelName->find('all');
no need to use {
}
curly braces
Upvotes: 1
Reputation: 8461
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
Upvotes: 1