Commit 13b7c8e8 by Qiang Xue

refactored Pjax. Added title change support. [skip ci]

parent a872d605
...@@ -89,15 +89,17 @@ class Pjax extends Widget ...@@ -89,15 +89,17 @@ class Pjax extends Widget
$this->options['id'] = $this->getId(); $this->options['id'] = $this->getId();
} }
ob_start();
ob_implicit_flush(false);
if ($this->requiresPjax()) { if ($this->requiresPjax()) {
ob_start();
ob_implicit_flush(false);
$view = $this->getView(); $view = $this->getView();
$view->clear(); $view->clear();
$view->beginPage(); $view->beginPage();
$view->head(); $view->head();
$view->beginBody(); $view->beginBody();
if ($view->title !== null) {
echo Html::tag('title', Html::encode($view->title));
}
} }
echo Html::beginTag('div', $this->options); echo Html::beginTag('div', $this->options);
} }
...@@ -108,32 +110,31 @@ class Pjax extends Widget ...@@ -108,32 +110,31 @@ class Pjax extends Widget
public function run() public function run()
{ {
echo Html::endTag('div'); echo Html::endTag('div');
if ($requiresPjax = $this->requiresPjax()) {
$view = $this->getView(); if (!$this->requiresPjax()) {
$view->endBody(); $this->registerClientScript();
$view->endPage(true); return;
} }
$view = $this->getView();
$view->endBody();
$view->endPage(true);
$content = ob_get_clean(); $content = ob_get_clean();
if ($requiresPjax) { // only need the content enclosed within this widget
// only need the content enclosed within this widget $response = Yii::$app->getResponse();
$response = Yii::$app->getResponse(); $level = ob_get_level();
$level = ob_get_level(); $response->clearOutputBuffers();
$response->clearOutputBuffers(); $response->setStatusCode(200);
$response->setStatusCode(200); $response->format = Response::FORMAT_HTML;
$response->format = Response::FORMAT_HTML; $response->content = $content;
$response->content = $content; $response->send();
$response->send();
// re-enable output buffer to capture content after this widget // re-enable output buffer to capture content after this widget
for (; $level > 0; --$level) { for (; $level > 0; --$level) {
ob_start(); ob_start();
ob_implicit_flush(false); ob_implicit_flush(false);
}
} else {
$this->registerClientScript();
echo $content;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment