Answer the question
In order to leave comments, you need to log in
How to update using Pajax - GridView with an image on button click?
There is such a code
public function actionRotate($id)
{
$model = $this->findModel($id);
Image::frame(UserImages::FILE_PATH . Yii::$app->user->identity->id . DIRECTORY_SEPARATOR . $model->image, 0, 0)
->rotate(90)
->save(UserImages::FILE_PATH . Yii::$app->user->identity->id . DIRECTORY_SEPARATOR . $model->image, ['jpeg_quality' => 100]);
if (Yii::$app->request->isAjax)
return $this->renderList();
else
return $this->redirect(['index']);
}protected function renderList()
{
$searchModel = new UserImagesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$modelImages = new UserImagesForm();
$dataProvider->sort->route = Url::toRoute(['index']);
$method = Yii::$app->request->isAjax ? 'renderAjax' : 'render';
return $this->$method('index', [
'dataProvider' => $dataProvider,
'modelImages' => $modelImages,
]);
}
<?php Pjax::begin(['id' => 'images-list','timeout' => 500, 'enablePushState'=>false]); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'label' => 'Image',
'format' => 'raw',
'value' => function($data){
return Html::img('uploads/images/user_'.Yii::$app->user->identity->id.'/'.$data->image,[
'style' => 'width:150px;'
]);
},
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{rotate}{delete}',
'buttons' => [
'rotate' => function ($url,$model) {
return Html::a(' <button type="button" class="btn btn-primary">'.Yii::t('app', 'Rotate').'</button>', $url,
[
'title' => Yii::t('app', 'Rotate'),
'data-method'=>'POST',
'data-pjax' => '#images-list',
]);
},
'delete' => function ($url,$model) {
return Html::a(' <button type="button" class="btn btn-danger">'.Yii::t('app', 'Delete').'</button>', $url,
[
'title' => Yii::t('app', 'Delete'),
'data-method'=>'POST',
'data-pjax' => '#images-list',
'data-confirm'=>Yii::t('app', 'Are you sure you want to delete this item?'),
]);
},
],
],
],
]); ?>
<?php Pjax::end(); ?></div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question