在Zend Framework 1.9应用程序中开始使用jQuery的最佳方法?
我想开始在我的Zend Framework应用程序中使用jQuery,但不确定哪种是最好的入门方法.我知道我可以像其他任何JavaScript库一样包含jQuery库,但是使用ZendX_JQuery有什么优点,以及在Zend Framework 1.9应用程序中开始使用它的必要步骤是什么?
I want to get started working with jQuery in my Zend Framework application but not sure which is the best way to get started. I know I could include the jQuery library just like any other javascript library, but what are the advantages of using ZendX_JQuery, and what are the steps necessary to start using it in my Zend Framework 1.9 application?
通过执行以下步骤,我能够使jQuery在1.9.4项目中正常工作:
I was able to get jQuery working in my 1.9.4 project by following these steps:
步骤1:将ZendX目录复制到您的库目录.您可以在Zend Framework下载的extras/library目录中找到ZendX.
Step 1: Copy the ZendX directory to your library directory. ZendX can be found in the extras/library directory of your Zend Framework download.
第2步:从 jqueryui.com 下载jQuery和jQuery UI库.我选择了UI亮度主题.
Step 2: Download jQuery and the jQuery UI library from jqueryui.com. I chose the UI Lightness theme.
第3步:提取下载文件并将jquery-ui-1.7.2重命名为jquery并移至您的 public/js 目录.
Step 3: Extract the download and rename jquery-ui-1.7.2 to jquery and move to your public/js directory.
第4步:将以下行添加到您的 bootstrap 文件中:
Step 4: Add these lines to your bootstrap file:
protected function _initViewHelpers()
{
$view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
$view->jQuery()->addStylesheet('/js/jquery/css/ui-lightness/jquery-ui-1.7.2.custom.css')
->setLocalPath('/js/jquery/js/jquery-1.3.2.min.js')
->setUiLocalPath('/js/jquery/js/jquery-ui-1.7.2.custom.min.js');
}
第5步:现在将jQuery视图帮助器添加到您的布局文件中:
Step 5: Now add the jQuery view helper to your layout file:
<head>
<?php echo $this->jQuery(); ?>
</head>
第6步:要测试所有功能是否正常运行,请将此行添加到您的视图脚本之一:
Step 6: To test that you have everything working, add this line to one of your view scripts:
Pick your Date: <?php echo $this->datePicker("dp1", '', array('defaultDate' => date('Y/m/d', time()))); ?>
现在,如果您在浏览器中打开此页面,则应该有一个文本字段.您应该能够单击文本字段,该文本字段会自动弹出一个已设置为UI Lightness主题样式的日历.
Now, if you open this page in your browser, there should be a text field. You should be able to click on the text field, which automatically pops up a calendar that has been styled to the UI Lightness theme.