cakephp如何添加脚本来查看

时间:2014-12-15 22:00:30

标签: cakephp

我希望在视图中添加一些脚本,并在默认布局中将其置于页面底部。它在加载查询之前运行并导致错误。

我正在使用cakephp 2.5

有没有办法缓冲它?

myview.ctp:

<script type="text/javascript">
  FWDEVPUtils.onReady(function(){

  FWDEVPlayer.useYoutube = "yes";
  FWDEVPlayer.videoStartBehaviour = "pause";

  new FWDEVPlayer({   
    //main settings
    instanceName:"player",
    parentId:"player",
    mainFolderPath:"content"
  });
});

default.thtml中

echo $this->Html->script('//code.jquery.com/jquery-1.10.2.min.js');
echo $this->Html->script('bootstrap.min');
echo $this->Html->script('FWDEVPlayer');

echo $this->fetch('script');
echo $this->Js->writeBuffer();

1 个答案:

答案 0 :(得分:2)

在myview.ctp中:

<?php $this->start('script'); ?>
<script type="text/javascript">
  FWDEVPUtils.onReady(function(){

  FWDEVPlayer.useYoutube = "yes";
  FWDEVPlayer.videoStartBehaviour = "pause";

  new FWDEVPlayer({   
    //main settings
    instanceName:"player",
    parentId:"player",
    mainFolderPath:"content"
  });
});
<?php $this->end(); ?>

您的脚本将包含在您编写的布局default.ctp中:     echo $ this-&gt; fetch('script');