Ejemplo n.º 1
0
 public function run()
 {
     if (!$this->model) {
         return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The model cannot be empty.'), ['class' => 'alert alert-danger']);
     }
     $hasFileBehavior = false;
     foreach ($this->model->getBehaviors() as $behavior) {
         if ($behavior->className() == FileBehavior::className()) {
             $hasFileBehavior = true;
         }
     }
     if (!$hasFileBehavior) {
         return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'), ['class' => 'alert alert-danger']);
     }
     Url::remember(Url::current());
     return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
         return Html::a("{$model->name}.{$model->type}", $model->getUrl());
     }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
         return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/attachments/file/delete', 'id' => $model->id], ['title' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post']);
     }]]]]);
 }
Ejemplo n.º 2
0
 public function behaviors()
 {
     return ['fileBehavior' => ['class' => \common\modules\attachments\behaviors\FileBehavior::className()]];
 }