2013-07-23 129 views
0

我有這樣的代碼我可以在變量設置中使用動態模型嗎?

$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

「不工作」 你是什麼意思?究竟發生了什麼?中間版本應該工作IMO。 – mark

+0

$模型的價值是什麼? – tlenss

+0

var_dump($ aux = $ this-> loadModel($ model)); – Hackerman

回答

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(); 
} 

?> 
相關問題