cakephp递归选择框2

| 我有
Tarifs
,每个tarif
hasMany
Price
Price
还有
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>\";
    ...     
我需要输入“ 7”作为选择,其中每个选项都显示组名,并将其“ 8”作为值。 user_group_id值很好,但是在文本输入中显示。我尝试过
$this->Form->select
$this->Form->input(...,\'type\'=>\'select\')
,但它们都提供了没有选项的选择框。 如何设置输入以执行所需的操作? 谢谢     
已邀请:
在您的控制器中,您需要添加:
$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)
    

要回复问题请先登录注册