0

I have this code

 $this->loadModel($model);
 $this->Task->id = $id;
 $this->Task->save($this->data[$model]);

How can I setup the "Task" model so I can make it dynamic because this doesn't work:

 $this->loadModel($model);
 $this->$model->id = $id;
 $this->$model->save($this->data[$model]);

I also tried this with no luck:

 $this->loadModel($model);
 $this->currentModel = $model;
 $this->currentModel->id = $id;
 $this->currentModel->save($this->data[$model]);
tereško
  • 58,060
  • 25
  • 98
  • 150
Justin Young
  • 2,393
  • 3
  • 36
  • 62

2 Answers2

0

Look at http://grahamwideman.wordpress.com/2009/08/05/php-grammar-notes/

You can wrap local variables in curly braces to evaluate the variable.

$this->{$model}->id = $id;
Tim Joyce
  • 4,487
  • 5
  • 34
  • 50
0

try this one...

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

?>
Scrappy Cocco
  • 1,192
  • 3
  • 21
  • 38