请考虑以下两个文件:
// view/index.phtml
echo \Phalcon\Tag::javascriptInclude("javascript/jquery.js");
// view/about/about.phtml
echo \Phalcon\Tag::javascriptInclude("javascript/x.js");
关于生成如下:
<script src="javascript/x.js">
<script src="javascript/jquery.js">
但x.js
文件取决于jquery.js
,因此它应放在它之前。
答案 0 :(得分:4)
假设您具有以下结构:
app/views/index.phtml
app/views/about/index.phtml
您可以在顶部的app/views/index.phtml
<?php echo \Phalcon\Tag::javascriptInclude("javascript/jQuery.js"); ?>
<?php echo \Phalcon\Tag::javascriptInclude("javascript/myother.js"); ?>
然后在app/views/about/index.phtml
<?php echo \Phalcon\Tag::javascriptInclude("javascript/x.js"); ?>
这会使jQuery.js
和myother.js
脚本在x.js
之前加载,因为x.js
将出现在主视图中
<?php echo $this->getContent() ?>
或者,您可以在主视图中设置:
<?php echo \Phalcon\Tag::javascriptInclude("javascript/jQuery.js"); ?>
<?php echo \Phalcon\Tag::javascriptInclude("javascript/myother.js"); ?>
<?php if ($is_about) { echo \Phalcon\Tag::javascriptInclude("javascript/myother.js"); } ?>
并在你的关于控制器
$this->view->setVar('is_about', TRUE);
HTH
答案 1 :(得分:2)
不确定它是否适合OP的使用案例,但对于其他搜索,这种模式非常有用:
class MyController extends Phalcon\Mvc\Controller
{
public function initialize()
{
$this->assets->addJs("/path/to/myjs.js");
[...etc]
文档: http://docs.phalconphp.com/en/latest/reference/assets.html