lithium\template\helper\Form::select PHP Method

select() public method

For example: $this->form->select('colors', array(1 => 'red', 2 => 'green', 3 => 'blue'), array( 'id' => 'Colors', 'value' => 2 )); Renders a '` element. $list array An associative array of key/value pairs, which will be used to render the list of options. $options array Any HTML attributes that should be associated with the `` element.
    public function select($name, $list = array(), array $options = array())
    {
        $defaults = array('empty' => false, 'value' => null);
        list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
        list($scope, $options) = $this->_options($defaults, $options);
        if ($scope['empty']) {
            $list = array('' => $scope['empty'] === true ? '' : $scope['empty']) + $list;
        }
        if ($template === __FUNCTION__ && $scope['multiple']) {
            $template = 'select-multi';
        }
        $raw = $this->_selectOptions($list, $scope);
        return $this->_render(__METHOD__, $template, compact('name', 'options', 'raw'));
    }

Usage Example

Beispiel #1
0
 public function select($name, $list = array(), array $options = array())
 {
     $defaults = array('multiple' => false, 'hidden' => true);
     $options += $defaults;
     $out = parent::select($name, $list, $options);
     if ($options['multiple'] && $options['hidden']) {
         return $this->hidden($name . '[]', array('value' => '', 'id' => false)) . $out;
     }
     return $out;
 }