Reputation: 5429
In Cakephp I have a model called Category
and I have another model called Page
. Now I connected the Page
with $belongsTo
to the Category
model.
Now I have a form where I can create a new Page
:
<?php echo $this->Form->create('Page', array('action' => 'create')); ?>
<?php echo $this->Form->input('title'); ?>
<?php echo $this->Form->input('text'); ?>
<?php echo $this->Form->end('Create new Page'); ?>
Now I want to add the possibility to select the category in the form. I think the solution is simple but I didn't found anything helpful so far...
Upvotes: 1
Views: 159
Reputation: 2655
in your form add this code
echo $this->Form->input('category_id');
now go to your Page controller, inside the appropriate action method, you add this code
$categories = $this->Page->Category->find('list');
$this->set(compact('categories'));
Upvotes: 2