Relationship of Tables with Cakephp

Asked

Viewed 92 times

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 am doing CRUD, but I would like to know how to create a select that contains the name of the categories, in the part of adding articles.

1 answer

1


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

For example, in your form for Article:

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

Recalling that the value of each item is the id category and the text will be the field defined as displayField in his Model.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.