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):
<!-- Path to jQuery library -->
<?php echo $this->headScript()->prependFile('/js/jquery.js?ver=1.2.6'); ?>
<!-- Path to jQuery-PHP library -->
<?php echo $this->headScript()->appendFile('/js/jquery.php.pack.js?ver=0.6'); ?>
<div id="test"></div>
Call AJAX in your current template:
<a href="#" <?php echo $this->Ajax(array('action'=>'ajax'), array('id'=>23), true)?> >Test Ajax</a>
It generate next code:
<a href="#" onclick='javascript:$.php("/index/ajax",{"id":23});return false;' >Test Ajax</a>