detect AJAX request and set layout automatically
This commit is contained in:
parent
cc4bcac7f8
commit
d9d85e2306
1 changed files with 21 additions and 0 deletions
|
@ -60,6 +60,9 @@
|
|||
|
||||
// Load POST-parameters
|
||||
$this->loadPostParams();
|
||||
|
||||
// Detect AJAX
|
||||
$this->detectAJAX();
|
||||
}
|
||||
|
||||
|
||||
|
@ -297,6 +300,24 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Detect an AJAX-request by checking the X-Requested-With
|
||||
* header and set the layout to 'ajax' in this case.
|
||||
*/
|
||||
private function detectAjax()
|
||||
{
|
||||
// Get request headers
|
||||
$headers = apache_request_headers();
|
||||
|
||||
// Check X-Requested-With header and set layout
|
||||
if(array_key_exists('X-Requested-With', $headers) && $headers['X-Requested-With'] == 'XMLHttpRequest') {
|
||||
if(!array_key_exists('layout', $this->getParams)) {
|
||||
$this->getParams['layout'] = 'ajax';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new URL-route.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue