Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getIsPjax method to Request, and add X-PJAX-URL header when redirect from pjax request #2531

Merged
merged 2 commits into from
Feb 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions framework/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ public function getIsAjax()
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
}

/**
* Returns wheter this is a PJAX request
* @return boolean wether this is a PJAX request
*/
public function getIsPjax ()
{
return $this->getIsAjax() && isset($_SERVER['HTTP_X_PJAX']) && $_SERVER['HTTP_X_PJAX']==true;
}

/**
* Returns whether this is an Adobe Flash or Flex request.
* @return boolean whether this is an Adobe Flash or Adobe Flex request.
Expand Down
4 changes: 3 additions & 1 deletion framework/web/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ public function redirect($url, $statusCode = 302)
$url = Yii::$app->getRequest()->getHostInfo() . $url;
}

if (Yii::$app->getRequest()->getIsAjax()) {
if (Yii::$app->getRequest()->getIsPjax()) {
$this->getHeaders()->set('X-PJAX-URL', $url);
} elseif (Yii::$app->getRequest()->getIsAjax()) {
$this->getHeaders()->set('X-Redirect', $url);
} else {
$this->getHeaders()->set('Location', $url);
Expand Down