Created
March 7, 2011 04:56
-
-
Save balupton/858091 to your computer and use it in GitHub Desktop.
Ajaxify a Website with Server Side Optimisations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Our Page Action | |
public function pageAction ( ) { | |
// Prepare our variables for our view | |
// ... | |
// Handle our view | |
return $this->awesomeRender('page.html'); | |
} | |
// Render Helper | |
public function awesomeRender ( $template ) { | |
// Get the full template path | |
$template_path = ... | |
// Render the template | |
$template_html = $this->view->render($template_path); | |
// Check for the XHR header | |
if ( IS_XHR ) { | |
// We are a AJAX Request, return just the template | |
$this->sendJson({'content':$template_html}); | |
} | |
else { | |
// Wrap the Template HTML with the Layout and proceed as normal | |
// ... | |
} | |
// Done | |
} |
Hi,
I use this little piece of code to output necessary DOM elements for classic and ajax requests :
$ajaxRequest = false;
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') $ajaxRequest = true;
[...]
You example above seems to be more elegant, but could you explain how it works ?
@tezqa I think its code is using the PHP Zend Framework
, which use the MVC pattern (http://en.wikipedia.org/wiki/Model-view-controller). You can learn more about Zend here http://framework.zend.com/manual/en/learning.quickstart.intro.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In reference to: https://github.com/balupton/History.js/wiki/Intelligent-State-Handling