I am using CakePHP to create a simple blog for myself. I want to have a rating system attached to each post.
I have loaded the ratings which look like this:
Controller
$this->set('ratings', $this->Ratings->find('all'));
I want to generate radio buttons on the view with the ratings. The ratings have the fields value
and label
. I could use a foreach
and loop around the ratings but I am wondering if the radio button helper in the form class can take a model object and generate the radio buttons?
I hope you understand what I mean.
You can pass an options attribute to the form helper.
<?=$this->Form->input('rating', array('type' => 'radio', 'options' => range(1, 10)))?>
$options = array(
'0' => 'Male',
'1' => 'FeMale'
);
$attributes = array(
'legend' => false,
'value' => 0
);
echo $this->Form->radio('type', $options, $attributes);