开发者

Where do I put inline script in head with Zend Framework?

I'm reading the manual here: http://zendframework.com/manual/en/zend.view.helpers.html

but I'm still confused. I have a script in my head that I'm converting to the layout/view for the Zend MVC:

&l开发者_如何学Ct;script type="text/javascript">
  var embedCode = '<object data="http://example.com" type="application/x-shockwave-flash" height="385" width="475"><param name="src" value="http://example.com" /><param name="allowfullscreen" value="true" /></object>'
</script>

I first tried to add it is an external file like this (in layout):

$this->headScript()->appendFile('js/embeddedVideo.js')->appendScript($onloadScript);
<head>
<?php echo $this->headScript(); ?>
</head>

Didn't really work, but anyway, I'm wanting to just add the script and not add it as an external file. How do I do that?

Thanks!


it's flash right? There a View Helpers wich are designed to put

  • Flash
  • Object
  • Quicktime

Code on your website.

     <?php echo $this->htmlFlash('/flash.swf'); ?>

You can read about this at the ZF Documentation for View Helpers ZF View Helper


If you are using jQuery, for onload events use jQuery helper:

$this->view->jQuery()->addOnload($onloadScript);

In the layout script:

<?= $this->getPluginLoader('helper')->isLoaded("JQuery") ? $this->JQuery() . "\n" : "" ?>

Notice that ArneRie pointed out: there are already separate view helpers for specific tasks.


If it was specific on the module, controller, action or something else, you could then consider using the headScript() helper. But if it's to be in every view, just put it directly in the layout head. No need to complicate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜