Table Relationships with CakePHP

0

I have two tables: artigos (id, categoria_id, titulo, texto, criacao) and categorias (id, nome) . And they have a relationship ( artigos.categoria_id => categorias.id ). And I'm doing CRUD, but I would like to know how to create a select that contains the name of the categories in the add articles part.

    
asked by anonymous 08.01.2015 / 13:00

1 answer

1

If your relationships are all working correctly, just use FormHelper , as is common, informing the related field that it already mounts the <select> corresponding to you.

For example, on your form for Article :

echo $this->Form->create('Artigo');
echo $this->Form->input('categoria_id');
echo $this->Form->end();

Remembering that the value of each item is the id of the category and the text will be the field set to displayField in your Model .

    
08.01.2015 / 13:32