cakephp drop down list?
Does Cak开发者_如何学CePHP have a form helper for html drop downs?
Yes, there's an explicit FormHelper::select
and array('type' => 'select')
and select fields are automatically created in certain circumstances for belongsTo relations.
The quick answer is yes:
echo $this->Form->input('fieldName2', array('type' => 'select', 'options' => $array_of_options));
If you have a helper inclusion already added to the controller, make sure you include the Form helper var $helper = array('Html', 'Javascript','Form',...);
.
Then in your views you can build forms like this:
<?php
echo $this->Form->create('ModelName', array('action' => 'nameOfAction'));
echo $this->Form->input('fieldName');
echo $this->Form->input('fieldName2', array('type' => 'select', 'options' => $array_of_options));
echo $this->Form->end(__('Submit', true));
?>
Just a tip to supplement the above (on point) answers: the find('list', $params) model method can often be very helpful in generating your drop down list arrays. Check out more information on that here: http://book.cakephp.org/view/449/find#find-list-810
精彩评论