TbHtml::fileField PHP Method

fileField() public static method

Generates a file field input.
See also: CHtml::fileField
public static fileField ( string $name, string $value = '', array $htmlOptions = [] ) : string
$name string the input name.
$value string the input value.
$htmlOptions array additional HTML attributes.
return string the generated input field.
    public static function fileField($name, $value = '', $htmlOptions = array())
    {
        return parent::fileField($name, $value, $htmlOptions);
    }

Usage Example

Exemplo n.º 1
0
    /**
     * Runs the widget.
     */
    public function run()
    {
        list($name, $id) = $this->resolveNameID();
        $this->resolveId($id);
        if ($this->hasModel()) {
            $input = TbHtml::activeFileField($this->model, $this->attribute, $this->htmlOptions);
        } else {
            $input = TbHtml::fileField($name, $this->value, $this->htmlOptions);
        }
        echo TbHtml::tag('span', $this->buttonOptions, $this->label . ' ' . $input);
        if ($this->assetPath !== false) {
            $this->publishAssets($this->assetPath);
            $this->registerCssFile('css/jquery.fileupload-ui.css');
            if ($this->registerJs) {
                $this->getClientScript()->registerCoreScript('jquery');
                $this->registerScriptFile('js/vendor/jquery.ui.widget.js', CClientScript::POS_END);
                $this->registerScriptFile('js/jquery.iframe-transport.js', CClientScript::POS_END);
                $this->registerScriptFile('js/jquery.fileupload.js', CClientScript::POS_END);
            }
        }
        if ($this->bindPlugin) {
            TbArray::defaultValue('dataType', 'json', $this->pluginOptions);
            $options = !empty($this->pluginOptions) ? CJavaScript::encode($this->pluginOptions) : '';
            $script = <<<EOD
jQuery('#{$id}')
    .fileupload({$options})
    .prop('disabled', !jQuery.support.fileInput)
    .parent().addClass(jQuery.support.fileInput ? undefined : 'disabled');
EOD;
            $this->getClientScript()->registerScript(__CLASS__ . '#' . $id, $script);
        }
    }
All Usage Examples Of TbHtml::fileField
TbHtml