在zend框架中包含js文件的最佳方法 [英] the best way to include js file in zend framework

查看:85
本文介绍了在zend框架中包含js文件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的php脚本中包含外部js文件。我正在关注zend framework.Right现在我在控制器的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文件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆