我正在使用CakePHP为自己创建一个简单的博客。我想在每个帖子上附上评级系统。
我已经加载了如下所示的评分:
控制器
$this->set('ratings', $this->Ratings->find('all'));
我想在视图上生成带有评级的单选按钮。评分包含字段value
和label
。我可以使用foreach
并循环评级,但我想知道表单类中的单选按钮助手是否可以获取模型对象并生成单选按钮?
我希望你理解我的意思。
答案 0 :(得分:5)
您可以将options属性传递给表单助手。
<?=$this->Form->input('rating', array('type' => 'radio', 'options' => range(1, 10)))?>
答案 1 :(得分:0)
$options = array(
'0' => 'Male',
'1' => 'FeMale'
);
$attributes = array(
'legend' => false,
'value' => 0
);
echo $this->Form->radio('type', $options, $attributes);