Posted By

nikefido on 12/03/10


Tagged

disable zendajaxxmlhttprequestzend layoutnorender


Versions (?)

Zend ajax controller - testing if ajax, turning off layout and disabling view file


 / Published in: PHP
 

Example controller used for AJAX requests - Disables layout, shows how to sent an action to not render a view (setNoRender) and adds some security checks.

  1. <?php
  2.  
  3. /******************************************
  4. App Async Controller for AJAX functionality
  5.  
  6. Module: App
  7. Controller: Async
  8.  
  9.  
  10. ******************************************/
  11.  
  12. class App_AsyncController extends Zend_Controller_Action {
  13.  
  14. public function init() {
  15. //Set no views to render in any action
  16. //You may wish to change this if you want to use a view file
  17. $this->getHelper('viewRenderer')->setNoRender();
  18.  
  19. //Ensure this is an AJAX request
  20. if(!$this->_request->isXmlHttpRequest()) {
  21. die(); //You may want to throw an Exception instead
  22. }
  23. }
  24.  
  25. public function someAction() {
  26. //Disable the layout.
  27. $this->getHelper('layout')->disableLayout();
  28. }
  29. }

Report this snippet  

You need to login to post a comment.