Home  >  Article  >  php教程  >  Yii2 framework study notes (9) -- pjax

Yii2 framework study notes (9) -- pjax

黄舟
黄舟Original
2016-12-30 10:22:371087browse

Pjax is a relatively new thing, which refers to pushState + ajax. It takes advantage of the new features of html5 to implement some of the refresh features of ajax. Moreover, because the url has changed, the browser's forward and backward functions can also be used normally. This The difference from ordinary ajax.

Yii2 has provided complete pjax support, which is relatively simple to implement. Just use Pjax::begin/Pjax::end to frame the areas that need to be refreshed in the view. The code in the controller does not need to be done separately. Special processing, the code is as follows

Yii2 framework study notes (9) -- pjax

#If the form is included in pjax and needs to be submitted, the pjax-data parameter needs to be added. The value does not matter.

In addition, you need to submit the pjax of the form. After submitting the form, you need to pay attention to two issues:

1. If the action of the form is inconsistent with the original address, it will cause the automatically generated pager to point to It is the action to submit the form. The pager must be redirected to the original address by adding the specified route to the dataProvider in the controller when it is generated

Yii2 framework study notes (9) -- pjax

2. If the original The url has parameters. When the form is submitted, the parameters will be lost. There are two ways to deal with it. One is to put the original parameters into the hidden field of the form. The other is to add the required parameters to the url in the controller, as follows

Yii2 framework study notes (9) -- pjax

The above is the content of Yii2 framework study notes (9) - pjax. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn