在Cakephp中,我有一个名为Category
的模型,我有另一个名为Page
的模型。现在我将Page
和$belongsTo
连接到Category
模型。
现在我可以创建一个新的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'); ?>
现在我想添加在表单中选择类别的可能性。我认为解决办法很简单,但是到目前为止我还没有找到任何有用的方法。
在表单中添加以下代码
echo $this->Form->input('category_id');
现在转到Page控制器,在适当的动作方法中,添加以下代码
$categories = $this->Page->Category->find('list');
$this->set(compact('categories'));