* @since 2.0 */ class Pjax extends Widget { public $links = 'a'; public function init() { ob_start(); ob_implicit_flush(false); echo '
'; } public function run() { echo '
'; $content = ob_get_clean(); $headers = Yii::$app->getRequest()->getHeaders(); if ($headers->get('X-Pjax') && ($selector = $headers->get('X-PJax-Container')) === '#' . $this->getId()) { // todo: send the response and terminate the application } else { $this->registerClientScript(); return $content; } } /** * Registers the needed JavaScript. */ public function registerClientScript() { $view = $this->getView(); PjaxAsset::register($view); $js = 'jQuery(document).pjax("' . Json::encode($this->links) . '", "#' . $this->getId() . '");'; $view->registerJs($js); } }