php – 在zend框架中包含js文件的最佳方法

前端之家收集整理的这篇文章主要介绍了php – 在zend框架中包含js文件的最佳方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的 PHP脚本中包含外部js文件.我正在关注zend framework.Right现在我在控制器的init函数添加js文件,就像这样.
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文件的正确方法吗?

JavaScript(以及图像,CSS,flash电影等)属于视图层,因此在那里配置它们.

对于全局包含的文件,将它们添加到您的布局中,例如

<!-- 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 *()方法,因此将首先显示全局文件,例如

<?PHP // views/scripts/index/index.phtml
$this->inlineScript()->appendFile($this->baseUrl('path/to/script.js'));
原文链接:https://www.f2er.com/php/133015.html

猜你在找的PHP相关文章