我有这段代码
$this->loadModel($model);
$this->Task->id = $id;
$this->Task->save($this->data[$model]);
如何设置“任务”模型,以便我可以将其设置为动态,因为这不起作用:
$this->loadModel($model);
$this->$model->id = $id;
$this->$model->save($this->data[$model]);
我也试过这个没有运气:
$this->loadModel($model);
$this->currentModel = $model;
$this->currentModel->id = $id;
$this->currentModel->save($this->data[$model]);
答案 0 :(得分:0)
查看http://grahamwideman.wordpress.com/2009/08/05/php-grammar-notes/
您可以用花括号包装局部变量来评估变量。
$this->{$model}->id = $id;
答案 1 :(得分:0)
尝试这个...
<?php
// THE DYNAMIC MODEL
App::Import('Model', $model);
$this->DynamicModel = new $model;
// USAGE EXAMPLE
function getModelColumns($model){
App::Import('Model', $model);
$this->DynamicModel = new $model;
print_r($this->DynamicModel->getColumnTypes());exit();
}
?>