The question relates only to when working on yii2 framework.
To briefly explain the code. This is the code view.
\yii\widgets\Pjax::begin(['id' => 'pjax-container']);
if(Yii::$app->request->isPjax) {
echo \yii\jui\DatePicker::widget([
'name' => 'date',
'value' => ",
]);
} else {
echo \yii\helpers\Html::button('Load Pjax', ['onclick' => "$.pjax.reload({container:'#pjax-container'});"]);
}
\yii\widgets\Pjax::end();
The bottom line is that when the page loads css jquery-ui will not load because it does not pass the condition Yii::$app->request->isPjax.
Because in the header of the page will not be referenced styles. Then when I do a reboot via pjax condition passes. And styles have loaded. But are only js files and js code.
And if I do not use pjax, and in the controller call renderAjax. In this case, everything works fine.
Even more simple example
\yii\widgets\Pjax::begin(['id' => 'pjax-container']);
if(Yii::$app->request->isPjax) {
$this->registerCssFile('http://test.css'); // not logged...
$this->registerJsFile('http://test.js'); // registers
}
echo \yii\helpers\Html::button('Load Pjax', ['onclick' => "$.pjax.reload({container:'#pjax-container'});"]);
\yii\widgets\Pjax::end();
Here is an example of work
clip2net.com/s/3y8hHIO and the result of the query
clip2net.com/s/3y8hMoH where we see that js checked, and CSS is not.
2. You are again attached for example, and why I assumed what I'm trying to hide the blocks. And I'm just as simply showed the problem of check styles when outputting content via pjax.
3. Unlike pjax from ajax about the difference php from yii2 =) working Principle of pjax is very simple. The addition of a dynamic element change pages, change the url using pushState. Additionally yii2 on request understands pjax requests and cuts of the content with pjax widget. Which by the way is not necessary.
4. I disagree with you. What content will return yii requests pjax script is a problem especially yii. And the fact that yii is based on the query cuts out a necessary part of it's only feature of yii. For which they should be commended. Consider 2 scenarios. 1. pjax should ONLY return the content. In this case, we do not need to register js files when prompted. And we get.
2. Yii needs to register all necessary scripts when prompted. And in this case we get a response to the registration js. But then why wasn't logged css.
In the example I pointed out that if some of the content we display via View::renderAjax then register js and css. What is logical and correct.
Now more real-world example of using pjax which will cause the specified me a problem. Again my example you do not like.
The object catalog. Using pjax, we display more of the object. And on the details page, we register the additional css needed to display this page. And we end up with the same problem. Css does not load. - gonzalo_Hay commented on July 9th 19 at 13:57
The example shows the check styles when rendering via pjax. I made even more simple example - gonzalo_Hay commented on July 9th 19 at 14:03
Now, regarding registration in the head. Nice try, but no.
\yii\widgets\Pjax::begin(['id' => 'pjax-container']);
if(Yii::$app->request->isPjax) {
$this->registerCssFile('test.css');
$this->registerJsFile('test.js', ['position' => \yii\web\View::POS_HEAD]);
} else {
echo \yii\helpers\Html::button('Load Pjax', ['onclick' => "$.pjax.reload({container:'#pjax-container'});"]);
}
\yii\widgets\Pjax::end();
?>
registers js, css, no. - gonzalo_Hay commented on July 9th 19 at 14:09
yii\widgets\Pjax - 144 row
// Do not re-send css files as it may override the css files that were loaded after them.
// This is a temporary fix for https://github.com/yiisoft/yii2/issues/2310
// It should be removed once pjax supports loading only missing css files
$view->cssFiles = null;
And if we will render using renderAjax styles are duplicated, and if they are using pjax them clean. Generally, in one case scored. And the other shut down everything. - gonzalo_Hay commented on July 9th 19 at 14:12