activeFileField() public static method

Generates a file field input for a model attribute.
See also: CHtml::activeFileField
public static activeFileField ( CModel $model, string $attribute, array $htmlOptions = [] ) : string
$model CModel the data model.
$attribute string the attribute.
$htmlOptions array additional HTML attributes.
return string the generated input field.
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);
        }
    }
Exemplo n.º 2
0
 /**
  * Renders a file field for a model attribute.
  * @param CModel $model the data model.
  * @param string $attribute the attribute.
  * @param array $htmlOptions additional HTML attributes
  * @return string the generated input field.
  * @see TbHtml::activeFileField
  */
 public function fileField($model, $attribute, $htmlOptions = array())
 {
     return TbHtml::activeFileField($model, $attribute, $htmlOptions);
 }
Exemplo n.º 3
0
 /**
  * Renders a file field for a model attribute.
  * This method is a wrapper of {@link TbHtml::activeFileField}.
  * Please check {@link TbHtml::activeFileField} for detailed information
  * about the parameters for this method.
  * @param CModel $model the data model
  * @param string $attribute the attribute
  * @param array $htmlOptions additional HTML attributes
  * @return string the generated input field
  */
 public function fileField($model, $attribute, $htmlOptions = array())
 {
     return $this->wrapControl(TbHtml::activeFileField($model, $attribute, $htmlOptions));
 }