Привет!
Загружаю файл на сервер средствами Yii2.
Модель:
public $attachment;
public function rules()
{
return [
[['sender_id', 'incoming_number', 'incoming_date', 'delivery_type_id', 'attachment'], 'required'],
[['sender_id', 'delivery_type_id', 'status_id'], 'integer'],
[['outgoing_date', 'incoming_date', 'status_id', 'created'], 'safe'],
[['attachment'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, xls, docx, pdf'],
[['comments'], 'string'],
[['outgoing_number', 'incoming_number', 'summary', 'attachment'], 'string', 'max' => 255],
[['status_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentStatus::className(), 'targetAttribute' => ['status_id' => 'id']],
[['delivery_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => DeliveryTypes::className(), 'targetAttribute' => ['delivery_type_id' => 'id']],
[['sender_id'], 'exist', 'skipOnError' => true, 'targetClass' => Senders::className(), 'targetAttribute' => ['sender_id' => 'id']],
];
}
Контроллер:
$model = new Documents();
if($model->load(Yii::$app->request->post()) && $model->validate()) {
$newDoc = new Documents();
$newDoc->sender_id = $model->sender_id;
$model->attachment = UploadedFile::getInstance($model, 'attachment');
$model->attachment->saveAs('uploads/documents/'.$model->attachment->name."-".date('YmdHis').$model->attachment->extension);
$newDoc->attachment = "filezzz";
}
При клике на сабмит пишет, что attachment не может быть пустым. Почему??? Я ведь назначаю ему значение