Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Radio Buttons

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.

like image 621
RailsSon Avatar asked Apr 21 '26 17:04

RailsSon


1 Answers

You can pass an options attribute to the form helper.

<?=$this->Form->input('rating', array('type' => 'radio', 'options' => range(1, 10)))?>
like image 131
Andrew Avatar answered Apr 24 '26 06:04

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!