zend framework(1.1)将javascript文件附加到页脚?

chr*_*lee 2 php zend-framework

是否有开箱即用的方式在视图脚本的页脚中加载某些javascripts?

这对谷歌分析等脚本特别有用.

或者这需要扩展$ this-> headScript()并创建$ this-> footScript()?

Roc*_*ord 6

在布局中使用占位符,$this->layout()->footScript然后将所需的代码附加到占位符.
或者你可以使用inlineScript()Helper.在将InlineScript助手具有相同的API是用HeadScript().
最佳可能是使用布局占位符和inlineScript帮助器.

inlineScript助手的示例:

//I use this in some of my controllers, in the predispatch()
$this->view->inlineScript()->setScript(
                "$('audio').mediaelementplayer();");

//then I just attach this to any view (including layout)
<?php echo $this->inlineScript() ?>
Run Code Online (Sandbox Code Playgroud)

使用占位符这样的东西,你可以在任何地方使用javascript.