Answer the question
In order to leave comments, you need to log in
How to work with Pjax in yii2?
i have a quick search form
<?php yii\widgets\Pjax::begin(['id' => 'new_note']) ?>
<?= Html::beginForm(['/system/system/fastsearch'], 'post', ['data-pjax' => '','enctype' => 'multipart/form-data', 'class'=>'form-inline' ]) ?>
<?= Html::input('text', 'search', "", ['class' => "form-control form-control-sm ml-3 w-75"]) ?>
<?= Html::submitButton('<i class="glyphicon glyphicon-search"></i> Найти', ['class' => 'btn btn-default', 'id'=>'press_search'])?>
<?= Html::endForm() ?>
<?php Pjax::end(); ?>
Answer the question
In order to leave comments, you need to log in
Good morning.
Pjax only deals with content between begin() and end().
Therefore, you can simply add the desired div after the form.
Form code.
<?php
yii\widgets\Pjax::begin(['id' => 'new_note', 'enablePushState' => false]) ?>
<?= Html::beginForm(['/system/system/fastsearch'], 'post', ['data-pjax' => '1','enctype' => 'multipart/form-data', 'class'=>'form-inline' ]) ?>
<?= Html::input('text', 'search', "", ['class' => "form-control form-control-sm ml-3 w-75"]) ?>
<?= Html::submitButton('<i class="glyphicon glyphicon-search"></i> Найти', ['class' => 'btn btn-default', 'id'=>'press_search'])?>
<?= Html::endForm() ?>
<div id="reload-pjax"><?= $search ?? null ?></div>
<?php Pjax::end();
?>
public function actionFastsearch()
{
if(Yii::$app->request->isAjax){
$search = Yii::$app->request->post('search');
return $this->render('index', ['search' => $search]);
}
}
<?php
Pjax::widget([
'id' => 'reload-pjax',
'enablePushState' => false,
'enableReplaceState' => false,
'formSelector' => '#options-form',
'submitEvent' => 'submit',])
?>
<?= Html::beginForm(['/site/fastsearch'],
'post',
[
'class'=>'form-inline',
'id' => 'options-form'
]) ?>
<?= Html::input('text', 'search', "", ['class' => "form-control form-control-sm ml-3 w-75"]) ?>
<?= Html::submitButton('<i class="glyphicon glyphicon-search"></i> Найти', ['class' => 'btn btn-default', 'id'=>'press_search'])?>
<?= Html::endForm() ?>
<div id="reload-pjax"></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question