Nvd\Crud\Html::select PHP Method

select() public static method

public static select ( $name, $options, $attributes = [], $selectedValue = null, $useKeysAsValues = false )
    public static function select($name, $options, $attributes = [], $selectedValue = null, $useKeysAsValues = false)
    {
        $output = static::startTag("select", array_merge(['name' => $name], $attributes));
        foreach ($options as $key => $value) {
            if ($useKeysAsValues) {
                $selectedAttr = $key === $selectedValue ? " selected" : "";
                $valueAttr = " value='{$key}'";
            } else {
                $selectedAttr = $value === $selectedValue ? " selected" : "";
                $valueAttr = "";
            }
            $output .= "<option{$selectedAttr}{$valueAttr}>{$value}</option>";
        }
        $output .= static::endTag("select");
        return $output;
    }

Usage Example

コード例 #1
0
 protected function showSelect()
 {
     return Html::select($this->name, $this->options, $this->attributes, $this->useOptionKeysForValues);
 }