在我看来,当我调用内联执行<?php echo $this->Html->script('forms/contact');?>
时,它执行正常,但是当我希望脚本在头标记中加载时,它会生成代码两次。
在我看来:
<?php $this->Html->script('forms/contact', array('inline' => false));?>
输出:
<script type="text/javascript" src="/animalmedica/js/forms/contact.js"></script>
<script type="text/javascript" src="/animalmedica/js/forms/contact.js"></script>
任何想法为什么?
答案 0 :(得分:1)
我无法回答你的问题,但我有完全相同的问题。经过一些反复试验,我想出了这个解决方案:
在我的默认布局中,我使用了fetch脚本方法和脚本进行布局。我只需要一个
echo $this->Html->charset();
echo $this->Html->meta('icon');
echo $this->Html->css('cake.generic');
echo $this->Html->css('grid_layout');
echo $this->Html->css('style');
echo $this->Html->css('jquery-ui-1.10.3.custom');
echo $this->Html->script('countdown');
echo $this->Html->script('page');
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');
echo $this->Js->writeBuffer(array('cache'=>FALSE));
//echo $scripts_for_layout;
现在不推荐使用布局脚本:
http://book.cakephp.org/2.0/en/views.html#using-blocks-for-script-and-css-files