public function save($runValidation = true, $attributes = NULL) { //adam: if ($this->eavType == 'boolean') { if ($this->value == '1') { $this->value = 'true'; } else { $this->value = 'false'; } } else { if ($this->eavType == 'file') { $configPath = Linet3Helper::getSetting("company.path"); $a = \yii\web\UploadedFile::getInstanceByName('Settings[' . $this->id . '][value]'); //var_dump($a); //exit; if ($a) { $this->value = $a; $ext = $this->value->extension; //$fileName = $yiiBasepath."/files/".$configPath."/settings/".$this->id.".".$ext; //echo $this->id.get_class($this); $logo = new \app\models\Files(); $logo->name = $this->id . "." . $ext; //it might be $img_add->name for you, filename is just what I chose to call it in my model $logo->path = "settings/"; $logo->parent_type = get_class($this); $logo->parent_id = $this->id; // this links your picture model to the main model (like your user, or profile model) $logo->public = true; $id = $logo->save(); // DONE //echo $logo->id; //Yii::$app->end(); if ($this->value->saveAs($logo->getFullFilePath())) { $this->value = $logo->hash; //"/files/".$configPath."/settings/".$this->id.".".$ext; } //Yii::$app->end(); } } } return parent::save($runValidation, $attributes); }
<label><?php echo Yii::t('app', 'Attached Files'); ?> </label> <?php echo \yii\helpers\Html::fileInput("Files" . '[' . $attribute . ']', null, ['accept' => 'image/*;capture=camera']); //$model->className() if (!$model->isNewRecord) { echo "<h2>" . Yii::t('app', 'Attached files') . "</h2>"; //echo get_class($model) . $model->id; //$files = new app\models\Files(); $files = new app\models\Files(['scenario' => 'search']); //$files->unsetAttributes(); $files->parent_type = get_class($model); $files->parent_id = $model->id; $files->hidden = 0; echo app\widgets\GridView::widget(array('id' => 'acc-template-grid', 'dataProvider' => $files->search([]), 'panel' => false, 'pjax' => false, 'columns' => array(array('attribute' => 'name', 'format' => 'raw', 'value' => function ($data) { return \yii\helpers\Html::a(\yii\helpers\Html::encode($data->name), yii\helpers\BaseUrl::base() . ("/data/download/" . $data->id)); }), array('attribute' => 'date', 'value' => function ($data) { return $data->readDateFormat($data->date); }), array('class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => array('delete' => function ($url, $model, $key) { // 'label' => '<i class="glyphicon glyphicon-trash"></i>', //'deleteConfirmation' => true, //'imageUrl' => false, return \yii\helpers\Html::a('Delete', Yii\helpers\BaseUrl::base() . "/files/delete/" . $model->id); }))))); }