Undefined property: Cake \ ORM \ Query

0

I have a question related to this other question I raised and in the end I found the solution:

Relationship between tables (hasOne)

When I want to do the same but only show a record according to the id that happens to the function, it returns the following error in all the fields of the query:

  

Notice (8): Undefined property: Cake \ ORM \ Query :: $ id   [APP / Template / Documents / documento.ctp, line 23]

What I do is in the Document controller I create a Document function, so that it shows the detail of a document:

public function escudo($idDocumento) {
    $documentos = TableRegistry::get('Documentos');
    $documento = $documentos->find()
                            ->where(['Documentos.id' => $idDocumento])
                            ->contain(['Imagenes']);
    /*debug($documento);*/
    $this->set('documento', $documento);
}

The query is assembled well and I've actually verified that $ idDocumento contains the value of the id, but it shows it as an object, so you can see if I debug $ idDocumento:

  

'4'

and if I debug a $ document:

  

....

     

'sql' = > 'SELECT Documents.id AS ..... WHERE Documents.id =: c0'

     

'params' = > [': c0' = > ['value' = > (int) 4, 'type' = >   'integer', 'placeholder' = > 'c0']],   .....

That: c0 is like a variable, I do not understand very well what happens but it is not interpreted by the view.

    
asked by Isaac Palacio 28.06.2018 в 18:00
source

1 answer

0

Well I found the solution was to put ->first() in the Document function:

public function documento($idDocumento) {
    $documentos = TableRegistry::get('Documentos');
    $documento = $documentos->find()
                            ->where(['Documentos.id' => $idDocumento])
                            ->contain(['Imagenes'])
                            ->first();
    /*debug($documento);*/
    $this->set('documento', $documento);
}
    
answered by 29.06.2018 в 00:00