M
M
Max DangerPro2016-11-26 04:32:10
JavaScript
Max DangerPro, 2016-11-26 04:32:10

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>

This is in the controller that removes the images:
public function actionDeleteimg($id) {
        $model = $this->findModel($id);
        $image = $model->getImages();
        if($image) {
            $model->removeImages();
        }
        return $this->redirect(['view''id' => $model->id]);
    }

I have everything loaded, updated, deleted but with a page reload. And you need to make sure that in the form, this block works without reloading the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-11-26
@DangerPro

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 question

Ask a Question

731 491 924 answers to any question