public function run() { if ($imageUrl = $this->model->getFileUrl($this->attribute)) { ?> <div class="file-input"> <div class="file-preview"> <div class="file-preview-thumbnails"> <div class="file-preview-frame"> <?php echo Html::img($imageUrl, ['class' => 'file-preview-image', 'alt' => \Yii::t('gromver.platform', 'File not found.')]); ?> </div> </div> <div class="clearfix"></div> </div> </div> <?php } if ($imageUrl == null) { // to show FileInput only for new upload echo KartikFileInput::widget(['model' => $this->model, 'attribute' => $this->attribute, 'options' => $this->options, 'pluginOptions' => $this->pluginOptions]); } else { FileInputAsset::register($this->getView()); ?> <div class="file-input"> <div class="input-group"> <div class="form-control file-caption "> <span class="glyphicon glyphicon-file"></span> <span class="file-caption-name"><?php echo $this->model->getFileName($this->attribute); ?> </span> </div> <div class="input-group-btn"> <?php echo Html::a('Remove Image', [$this->deleteAction, 'pk' => $this->model->getPrimaryKey(), 'attribute' => $this->attribute], ['class' => 'btn btn-danger', 'data-method' => 'post']); ?> </div> </div> </div> <?php } }
/** * Registers the needed assets */ public function registerAssets() { $view = $this->getView(); FileInputAsset::register($view); $this->setPluginDefault('browseLabel', Yii::t('fileinput', 'Browse') . '…'); $this->setPluginDefault('uploadLabel', Yii::t('fileinput', 'Upload')); $this->setPluginDefault('removeLabel', Yii::t('fileinput', 'Remove')); $this->registerPlugin('fileinput'); }