views:

312

answers:

3

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:

<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!

A: 

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.

Brenton Alker
+1  A: 

Hi,

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

ArneRie
+1  A: 

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.

takeshin