【发布时间】:2015-01-27 19:36:01
【问题描述】:
我只想在下拉列表中加载主要类别(而不是子类别)名称。我已经尝试了足够多,但无法成功。这个网站上有很多答案,我试图以这种方式解决我的问题,但不能。类别表如下,与 Tree 中的 cakephp 文档相同。
类别表属性
标识 |父ID |左下角|对|名称|
我尝试了以下链接中给出的这些技术 How to populate drop-down list with database values in CakePHP
创建类别的控制器的完整代码如下。
if ($this->request->is('post')) {
$this->Category->create();
if ($this->Category->save($this->request->data)) {
$this->Session->setFlash(__('Category has been saved.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to add Category.'));
}
else
$categories = $this->Category->find('list');
$this->set(compact('categories'));
return $this;
}
category.ctp的代码是
<?php echo $this->Form->create('Category'); ?>
<fieldset>
<legend><?php echo __('Add Category'); ?>
</legend>
<?php
$form->input('id');
// echo $this->Form->input('id');
echo $this->Form->input('name');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
现在请建议我在下拉列表中加载数据的解决方案。
【问题讨论】:
-
对于未来的问题,请务必提及您的确切 CakePHP 版本!
-
好的,我会的,cakephp 版本是 2.5
标签: php cakephp drop-down-menu