Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

181 lines (158 sloc) 7.486 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jQuery PHP library: Zend Framework</title>
<meta name="keywords" content="php, ajax, jquery, javascript" />
<meta name="description" content="jQuery PHP library" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="javascript/jquery.js" type="text/javascript"></script>
<script src="javascript/jquery.php.js" type="text/javascript"></script>
<script type="text/javascript" src="http://scripts.hohli.com/brush/shCore.js"></script>
<script type="text/javascript" src="http://scripts.hohli.com/brush/shBrushJScript.js"></script>
<script type="text/javascript" src="http://scripts.hohli.com/brush/shBrushXml.js"></script>
<script type="text/javascript" src="http://scripts.hohli.com/brush/shBrushPhp.js"></script>
<link type="text/css" rel="stylesheet" href="http://scripts.hohli.com/brush/styles/shCore.css"/>
<link type="text/css" rel="stylesheet" href="http://scripts.hohli.com/brush/styles/shThemeDefault.css"/>
<script type="text/javascript">
SyntaxHighlighter.config.clipboardSwf = 'http://scripts.hohli.com/brush/clipboard.swf';
SyntaxHighlighter.all();
</script>
</head>
<body>
<!-- start header -->
<div id="header">
<h1><a href="http://jquery.hohli.com">jQuery PHP</a></h1>
</div>
<!-- end header -->
<!-- start page -->
<div id="page">
<!-- start content -->
<div id="content">
<div class="post">
<a name="advanced"></a>
<h2 class="title">Zend Framework integration</h2>
<p class="meta">For advanced users</p>
<div class="entry">
<h3>Library</h3>
Copy <b>jQuery.php</b> and <b>jQuery</b> folder to your "library" directory.
<br/>
<br/>
<h3>Bootstrap</h3>
Add new action helper path:
<pre class="brush: php;">
require_once 'Zend/Controller/Action/HelperBroker.php';
Zend_Controller_Action_HelperBroker::addPrefix('ZendY_JQuery_Controller_Action_Helper');
</pre>
Add path to jQuery view helpers:
<pre class="brush: php;">
// 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_');
</pre>
<br/>
<h3>Controller</h3>
You can create new controller, or use any exist:
<pre class="brush: php;">
/**
* 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();
}
</pre>
<br/>
<h3>View</h3>
Include JavaScript in current action of controller ("view" where your use AJAX):
<pre class="brush: php;">
<!-- Path to jQuery library -->
&lt;?php echo $this->headScript()->prependFile('/js/jquery.js?ver=1.2.6'); ?&gt;
<!-- Path to jQuery-PHP library -->
&lt;?php echo $this->headScript()->appendFile('/js/jquery.php.pack.js?ver=0.6'); ?&gt;
<div id="test"></div>
</pre>
Call AJAX in your current template:
<pre class="brush: php;">
<a href="#" rel="nofollow" &lt;?php echo $this->Ajax(array('action'=>'ajax'), array('id'=>23), true)?&gt; >Test Ajax</a>
</pre>
It generate next code:
<pre class="brush: php;">
<a href="#" rel="nofollow" onclick='javascript:$.php("/index/ajax",{"id":23});return false;' >Test Ajax</a>
</pre>
</div>
</div>
<div class="post">
<a name="simple"></a>
<h2 class="title">Zend Framework integration</h2>
<p class="meta">Simple way</p>
<div class="entry">
<h3>Library</h3>
Copy <b>jQuery.php</b> and <b>jQuery</b> folder to your "library" directory.
<br/>
<br/>
<h3>Controller</h3>
You can create new controller, or use any exist:
<pre class="brush: php;">
/**
* 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();
}
</pre>
<br/>
<h3>View</h3>
Include JavaScript in current action of controller ("view" where your use AJAX):
<pre class="brush: php;">
<!-- Path to jQuery library -->
&lt;?php echo $this->headScript()->prependFile('/js/jquery.js?ver=1.3.2'); ?&gt;
<!-- Path to jQuery-PHP library -->
&lt;?php echo $this->headScript()->appendFile('/js/jquery.php.pack.js?ver=0.6'); ?&gt;
<div id="test"></div>
</pre>
Call AJAX in your current template
<pre class="brush: php;">
<a href="#" onclick="javascript:$.php('&lt;?php echo $this->Url(array('action'=>'ajax')?&gt;',&lt;?php Zend_Json::encode(array("id"=>23))?&gt;);return false;">click me</a>
</pre>
</div>
</div>
</div>
<!-- end content -->
</div>
<!-- end page -->
<div id="footer">
<p id="legal">&copy;2007 All Rights Reserved. | Developed by <a href="http://anton.shevchuk.name/">Anton Shevchuk</a></p>
<p id="links"> </p>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.