【问题标题】:cakephp select box with recursive 2cakephp 递归选择框 2
【发布时间】:2011-08-06 13:14:43
【问题描述】:

我有Tarifs,每个资费hasMany PricePrice 还有belongsTo UserGroup。所以基本上价格会随着用户组的变化而变化 - 没那么重要。

视图是这样的

<?php echo $this->Form->create('Tarif');?>
    ...
        $i=0;
        foreach ($this->data['Price'] as $price) {

            echo "<tr><td>".$this->Form->input("Price.$i.price", array('label' => false))."</td>";
            echo "<td>".$this->Form->input("Price.$i.currency", array('label' => false))."</td>";
            echo "<td>".$this->Form->input("Price.$i.UserGroup.id", array('label' => false))."</td>";
    ...     

我需要 UserGroup.id 输入以显示为选择,其中每个选项显示组名并将其 id 作为值。 user_group_id 值很好,但显示在文本输入中。我试过$this-&gt;Form-&gt;select$this-&gt;Form-&gt;input(...,'type'=&gt;'select') 但他们都提供了没有选项的选择框。 如何设置输入以执行我想要的操作? 谢谢

【问题讨论】:

  • 可以加pr($price);并向我们​​展示您的阵列之一?你是对的 $this->form->input(array('type'=>'select', 'option'=>$price['UserGroup']['name']));注意:这是一个盲目的回应。

标签: php cakephp-1.3 drop-down-menu


【解决方案1】:

在你的控制器中,你需要添加:

$user_groups = $this->UserGroup->find('list');
$this->set(compact('user_groups');

然后在视图中,您可以像这样设置下拉菜单:

<?php echo $this->Form->input('user_group', array('options' => $user_groups)); ?>

然后您可以将 $user_groups 作为选项添加到任何 Form->input 中,使用时它将成为一个下拉列表:

array('options' => $user_groups)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多