Answer the question
In order to leave comments, you need to log in
Yii 1.* uploading files?
if we take this instruction as a basis yiiframework.ru/doc/cookbook/ru/form.file.upload
then the image field is a field in the table required?
when you select a photo and click create, I get
The following errors need to be corrected:
The "Image" field must be filled in.
public function beforeSave()
{
if (!parent::beforeSave())
return false;
if (CUploadedFile::getInstance($this, 'document') != null)
{
if (($this->scenario == 'insert' || $this->scenario == 'update') &&
($document = CUploadedFile::getInstance($this, 'document'))
)
{
$this->deleteDocument(); // старый документ удалим, потому что загружаем новый
$this->document = $document;
$this->document->saveAs(
Yii::getPathOfAlias('webroot.media') . DIRECTORY_SEPARATOR . $this->document);
}
}
return true;
}
Answer the question
In order to leave comments, you need to log in
the fat model turned out to be unviable
, implemented it like this des1roer.blogspot.ru/2015/07/yii.html
It is required by default. It is necessary to specify allowEmpty=>true in the model in the file validator
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question