我有一个问题是将css资产添加到从view layout.phtml调用的集合中
这是我的代码:
<?php echo $this->tag->getDoctype() ?>
<html>
<head>
<?php $this->assets->outputCss('header') ?>
</head>
<body>
<?php $this->assets->get('header')->addCss('test.css'); ?>
<?php $this->assets->get('footer')->addJs('test.js'); ?>
<?php $this->assets->outputJs('footer') ?>
</body>
</html>
这是在浏览器中输出的:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript" src="/test.js"></script>
</body>
</html>
为什么头部没有CSS标签的输出?
答案 0 :(得分:1)
Assets组件基本上是这样的:
假设您提到的视图通过此控制器显示:
use Phalcon\Mvc\Controller;
class IndexController extends Controller
{
public function index()
{
// Add your header assets here
$this->assets
->collection('header')
->addCss('test.css');
// Add your footer assets here
$this->assets
->collection('footer')
->addJs('test.js');
}
}
现在您的观点应如下所示:
<?php echo $this->tag->getDoctype() ?>
<html>
<head>
<?php $this->assets->outputCss('header') ?>
</head>
<body>
<?php $this->assets->outputJs('footer') ?>
</body>
</html>