【问题标题】:CakePHP Radio ButtonsCakePHP 单选按钮
【发布时间】:2011-07-27 15:30:42
【问题描述】:

我正在使用 CakePHP 为自己创建一个简单的博客。我想为每个帖子附加一个评分系统。

我加载了如下所示的评分:

控制器

$this->set('ratings', $this->Ratings->find('all'));

我想在视图上生成带有评分的单选按钮。评级具有字段valuelabel。我可以使用foreach 并循环评分,但我想知道表单类中的单选按钮助手是否可以采用模型对象并生成单选按钮?

希望你明白我的意思。

【问题讨论】:

    标签: php forms cakephp radio-button


    【解决方案1】:

    您可以将选项属性传递给表单助手。

    <?=$this->Form->input('rating', array('type' => 'radio', 'options' => range(1, 10)))?>
    

    【讨论】:

    • 得到了欢呼。以错误的顺序传递选项和 html 属性。再次感谢。
    【解决方案2】:
    $options = array(
        '0' => 'Male',
        '1' => 'FeMale'
    );
    
    $attributes = array(
        'legend' => false,
        'value' => 0
    );
    
    echo $this->Form->radio('type', $options, $attributes);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 2011-03-13
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多