Answer the question
In order to leave comments, you need to log in
Working with the extension - yii2-images?
I am using the yii2-images
extension to load and display images.
I did the download and output, but the deletion by pressing the button with PJAX does not work. Or as an alternative, when a new image is uploaded, the old one will be deleted. This needs to be done somehow in PJAX. Help please, otherwise I don’t know JavaScript))
Link to the extension: https://github.com/CostaRico/yii2-images
This code is displayed in ActiveForm:
<fieldset>
<legend class="legFormAd">Обложка книги</legend>
<?= $form->field($model, 'image')->fileInput() ?>
<? $image = $model->getImage(); ?>
<? Pjax::begin([]);?>
<img src='<?=$image->getUrl() ?>' width="300"><br><br>
<? Pjax::end(); ?>
<?= Html::a('Удалить изображение', ['deleteimg', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Вы уверены, что хотите удалить эту обложку?',
'method' => 'post',
],
]) ?>
</fieldset>
public function actionDeleteimg($id) {
$model = $this->findModel($id);
$image = $model->getImages();
if($image) {
$model->removeImages();
}
return $this->redirect(['view', 'id' => $model->id]);
}
Answer the question
In order to leave comments, you need to log in
1. Wrap in pjax
2. Remove the redirect from the controller and return the block to be inserted instead of the one wrapped in pjax.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question