在我的组件可以调用 sfResponse::addJavascript() 之前,我的 layout.php 调用了 include_javascripts()。是否有“ helper ”或“最佳实践”来处理这个问题?
我是否必须将调用 sfResponse::addJavascript() 分开?我很乐意避免它。
这是我的实际解决方法:
<head>
<?php $nav = get_component('nav', 'nav') /* Please show me a better way. */ ?>
<?php include_javascripts() ?>
...
</head>
<body>
<?php /* include_component('nav', 'nav') */ ?>
<?php echo $nav ?>
...
</body>
谢谢
最佳答案
发件人:http://www.symfony-project.org/book/1_2/07-Inside-the-View-Layer
文件包含配置
//在view.yml中
indexSuccess:
stylesheets: [mystyle1, mystyle2]
javascripts: [myscript]
// Action 中
$this->getResponse()->addStylesheet('mystyle1');
$this->getResponse()->addStylesheet('mystyle2');
$this->getResponse()->addJavascript('myscript');
//在模板中
<?php use_stylesheet('mystyle1') ?>
<?php use_stylesheet('mystyle2') ?>
<?php use_javascript('myscript') ?>
关于php - Symfony 组件应该如何添加 JavaScript 和 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2257283/