I’m learning about CakePHP, with some videotutorials which are made with CakePHP 1.x. I’m using CakePHP 2.2.2 stable which is the latest version, and when I try to implement the edit function, I’m having this error:
Warning (2): Illegal offset type [CORE\Cake\Model\Model.php, line
2666]
This is the code of edit function:
function edit($id = null){
if(!$id){
$this->Session->setFlash('Tarea invalida');
$this->redirect(array('action'=>'index'),null,true);
}
if(empty($this->data)){
$this->data = $this->Tarea->find(array('id'=>$id));
}else{
if($this->Tarea->save($this->data)){
$this->Session->setFlash('La tarea ha sido salvada');
$this->redirect(array('action'=>'index'),null,true);
}else{
$this->Session->setFlash('La tarea no ha podido ser salvada. Intentelo de nuevo');
}
}
}
And I changed
$this->data = $this->Tarea->find(array('id'=>$id));
to
$this->data = $this->Tarea->find('all',array('conditions',array('id'=>$id)));
and the error doesn’t appear but no data is being retrieved of database…
if I implement:
$this->data = his->Tarea->find('first',array('conditions',array('id'=>$id)));
the first value always is being retrieved.
Hope your help, Daniel
The following part of your
findstatements is wrong:array('conditions',array('id'=>$id)). It has to be:array('conditions' => array('id'=>$id)).