【问题标题】:How to add JS or CSS files to the end of the queue from the controller action in Zend Framework?如何在 Zend Framework 中的控制器操作中将 JS 或 CSS 文件添加到队列末尾?
【发布时间】:2016-10-26 18:22:37
【问题描述】:

我已经阅读了很多关于此的主题(帖子末尾的列表),但我无法让我的代码正常工作。首先我使用的是旧的 Zend Framework 1.11。我有以下布局(只是一个例子):

<?php
    $this->headScript('file','/js/jquery/jquery-1.12.4.min.js');
    $this->headScript('file','/js/jquery/jquery-migrate-1.4.1.min.js');
    // more CSS & JS files goes here
    // some PHP code  goes here
?>
<html>
    <head>
        <?php
           echo $this->headLink();
           echo $this->headStyle();
           echo $this->headScript();
           echo $this->headInline();
        ?> 
    </head>
    ...
</html> 

这是我控制器的功能:

public function indexAction()
{
    $this->view->headScript()->appendFile('/js/jsgrid.js', 'text/javascript');
    $this->_helper->layout->setLayout('admin_console');
}

jsgrid.js 处的代码取决于要加载的 jQuery。我想从控制器加载文件作为最后一个,所以结果会是这样的:

<script type="text/javascript" src="/js/jquery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.4.1.min.js"></script>
<script type="text/javascript" src="/js/jsgrid.js"></script>

但是从上面的代码中我得到了这个:

<script type="text/javascript" src="/js/jsgrid.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="/js/jquery/jquery-migrate-1.4.1.min.js"></script>

导致脚本失败的原因。我怎样才能做到这一点?有什么建议吗?

主题列表:

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    经过多次尝试,我终于找到了解决方案:

    $this->view->inlineScript()->appendFile('/js/jsgrid.js', 'text/javascript');
    

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多