Automagically assign values of option tag in cakephp

To create an <option value="custom_value"> tag with custom values in cakephp, you just have to assign an associative array to option attribute of select tag like below example.

  <?php

     $item_list = array('7'=>'mouse','10'=>'keyboard','11'=>'video card');

     //cakephp way of creating select tag
     ...
     echo $form->input('sel1', array(
                                  'type'=>'select',
                                  'options'=>array($item_list),
				  'label'=>'Item',
				  'empty'=>'Select item...',)
			         );

  ?>

It will generate below html tag

Leave a Comment