the best way to include js file in zend framework(在 Zend 框架中包含 js 文件的最佳方法)
问题描述
我想在我的 php 脚本中包含外部 js 文件.我正在关注 zend 框架.现在我正在像这样在控制器的 init 函数中添加 js 文件.
I want to include external js file in my php script. I am following zend framework.Right now I am adding js file in controller's init function like this.
public function init() {
$this->doUserAuthorisation();
parent::init();
$this->view->headScript()->appendFile($this->view->baseUrl().'/js/front_cal/jquery-1.3.2.min.js');
$this->view->headLink()->setStylesheet($this->view->baseUrl().'/styles/front_cal/calendar.css');
}
我面临的问题是,js文件不包含.这是包含js文件的正确方法吗?
problem what i am facing is, js file doesnot include.Is this the right way to include js file?
推荐答案
JavaScript(和图像、CSS、Flash 电影等)属于视图层,所以在那里配置它们.
JavaScript (and images, CSS, flash movies, etc) belong to the view layer so configure them there.
对于全局包含的文件,将它们添加到您的布局中,例如
For globally included files, add them to your layout, eg
<!-- layout.phtml -->
<head>
<?php echo $this->headScript()->prependFile(
$this->baseUrl('path/to/file.js')) ?>
<?php echo $this->headLink()->prependStylesheet(
$this->baseUrl('path/to/file.css')) ?>
<!-- snip -->
<?php echo $this->inlineScript()->prependFile(
'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js') ?>
</body>
然后您的视图脚本可以将资产添加到在布局中回显的助手.由于布局使用了prepend*()方法,所以会先显示全局文件,例如
Your view scripts can then add assets to the helpers which are echoed out in the layout. As the layout uses the prepend*() methods, the global files will be displayed first, eg
<?php // views/scripts/index/index.phtml
$this->inlineScript()->appendFile($this->baseUrl('path/to/script.js'));
这篇关于在 Zend 框架中包含 js 文件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Zend 框架中包含 js 文件的最佳方法
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
