Answer the question
In order to leave comments, you need to log in
Why does image upload validation fail, yii2?
I'm trying to upload a picture, but the field does not pass validation, it says "you need to upload a file."
The form:
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
<?= $form->field($model, 'passport')->fileinput()->label(false) ?>
<?= Html::submitButton('Отправить') ?>
<?php ActiveForm::end() ?>
public function rules()
{
return [
[['passport'], 'file', 'extensions' => 'png, jpg'],
];
}
public function upload(){
if ($this->validate()){
$path = 'img/store/' . $this->passport->baseName . '.' . $this->passport->extension;
$this->passport->saveAs($path);
return true;
}else{
return false;
}
}
public function actionCreate()
{
$model = new Clients();
$model->passport = UploadedFile::getInstance($model, 'passport');
if($model->passport){
$model->upload();
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->save()) {
Yii::$app->session->setFlash('success', 'Спасибо, мы получили вашу анкету. В скором времени мы с вами свяжемся.');
} else {
Yii::$app->session->setFlash('error', 'Ошибка... Попробуйте еще раз...');
}
return $this->refresh();
}
return $this->render('create', [
'model' => $model,
]);
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Try doing this:
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->passport = UploadedFile::getInstance($model, 'passport');
if($model->passport){
$model->upload();
}
// остальной код действия.
}
if ($model->save()) {
Yii::$app->session->setFlash('success', 'Спасибо, мы получили вашу анкету. В скором времени мы с вами свяжемся.');
$path = Yii::getAlias('@web') . 'img/store/' . $this->passport->baseName . '.' . $this->passport->extension;
vskidka
select count (*)
from table1
where (A> 0) and (B < 9)
With the conditions it is not entirely clear from the question, but I hope it will not be difficult to prescribe the necessary ones.
"But the condition is also suitable for me if in one record A>0, and in the other record B<9."
If so, then instead of AND use OR
upd:
join's are easier to solve:
select count(*) as total
from table1 as t1 inner join table1 as t2
where t1.a > 0 and t2.b < 9
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question