public function beforeValidate() { if (!Yii::$app->user->isGuest && $this->isNewRecord) { $this->owner_id = Yii::$app->user->identity->id; } return parent::beforeValidate(); }
public function beforeValidate() { if ($this->isNewRecord) { $this->file_orig_name = $this->imageFile->name; $this->file_ext = $this->imageFile->extension; $this->title = $this->imageFile->name; $this->file_sys_name = self::$fileTempName; $this->description = 'To zdjęcie nie ma jeszcze opisu.'; if (!Yii::$app->user->isGuest) { $this->owner_id = Yii::$app->user->identity->id; } else { throw new \app\components\exceptions\FormException('Musisz być zalogowany by wgrać plik.'); } } return parent::beforeValidate(); }