Zend Framework integration

For advanced users

Library

Copy jQuery.php and jQuery folder to your "library" directory.

Bootstrap

Add new action helper path:
			    
                require_once 'Zend/Controller/Action/HelperBroker.php';
                Zend_Controller_Action_HelperBroker::addPrefix('ZendY_JQuery_Controller_Action_Helper');
	            
Add path to jQuery view helpers:
	            // add new View helpers Path
                require_once 'Zend/Layout.php';
                 
                $layout = Zend_Layout::startMvc($config->layout);
                $layout->getView()->addHelperPath(APPLICATION_PATH . '/../library/ZendY/JQuery/View/Helper',
                                                 'ZendY_JQuery_View_Helper_');
	            

Controller

You can create new controller, or use any exist:
                 /**
                  * ajaxAction
                  *
                  * @access public
                  * @created Tue Jun 10 17:50:24 EEST 2008
                  */
                  public function ajaxAction()
                  {
                      // init Jquery action helper - requried
                      $this->_helper->getHelper('Jquery');
                      // check XML HTTP Request if needed
                      if ($this->_helper->getHelper('Jquery')->error('error', 'error')) {
                      // forward to Error Controller, Error Action
                      return false;
                      }
                      // assign to div with id = 'test' current time
                      jQuery('div#test')->html(date('H:i:s'));
                      // output response - requried
                      $this->_helper->getHelper('Jquery')->sendResponse();
                  }
                

View

Include JavaScript in current action of controller ("view" where your use AJAX):
                
                <?php echo $this->headScript()->prependFile('/js/jquery.js?ver=1.2.6'); ?>
                
                <?php echo $this->headScript()->appendFile('/js/jquery.php.pack.js?ver=0.6'); ?>
                 
                
Call AJAX in your current template:
                    Ajax(array('action'=>'ajax'), array('id'=>23), true)?> >Test Ajax
                
It generate next code:
                    Test Ajax
                

Zend Framework integration

Simple way

Library

Copy jQuery.php and jQuery folder to your "library" directory.

Controller

You can create new controller, or use any exist:
                 /**
                  * ajaxAction
                  *
                  * @access public
                  * @created Tue Jun 10 17:50:24 EEST 2008
                  */
                  public function ajaxAction()
                  {
                      // check is AJAX request or not
                      if (!$this->getRequest() -> isXmlHttpRequest()) {
                          $this->getResponse() -> setHttpResponseCode(404)
                                               -> sendHeaders();
                          $this->renderScript('empty.phtml');
                          return false;
                      }
                      // assign to div with id = 'test' current time
                      jQuery('div#test')->html(date('H:i:s'));
                      // output response
                      jQuery()->getResponse();
                  }
                

View

Include JavaScript in current action of controller ("view" where your use AJAX):
                    
                    <?php echo $this->headScript()->prependFile('/js/jquery.js?ver=1.3.2'); ?>
                    
                    <?php echo $this->headScript()->appendFile('/js/jquery.php.pack.js?ver=0.6'); ?>
                    
Call AJAX in your current template
                    23))?>);return false;">click me