Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.5.0
-
Fix Version/s: None
-
Component/s: Zend_Layout, Zend_View
-
Labels:None
Description
Suppose a view helper like this:
class My_View_Helper_Glow
{
protected $view = null;
protected $cnt = 1;
/**
* Set the view so it can be used in the helper
*
* @param Zend_View $view
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
$this->_attachHeadScripts();
}
/**
* Attaches the needed scripts in the html header
*
*/
private function _attachHeadScripts()
{
$this->view->headScript()->appendFile('/scripts/swfobject.js');
$this->view->headScript()->appendFile('/scripts/sIFR/sifr.js');
$this->view->headLink()->appendStylesheet('/scripts/sIFR/sIFR-screen.css');
}
public function glow($text, $align = 'center', $case = 'upper', $bgcolor = null, $color = '#c4dce2')
{
$cnt = $this->cnt++;
$id = 'sifr_glow_' . $cnt;
$this->view->inlineScript()->appendScript('
if(typeof sIFR == "function"){
sIFR.replaceElement(
named({
sSelector : "span#' . $id . '"
,sFlashSrc : "/scripts/fonts/helvetica_blue_glow.swf"
,sColor : "' . $color . '"
' . ($bgcolor? ',sBgColor:"' . $bgcolor. '"' : ',sWmode:"transparent"') . '
,sCase : "' . $case . '"
,sFlashVars : "textalign=' . $align . '"
})
);
};
');
$return = '
<span class="sifr" id="' . $id . '">' . $text . '</span>
';
return $return;
}
}
So we add headScript and headLink items through a View Helper.
Now when this view helper is used in a layout file, than the scripts will not become attached, while they will if used in a controller action view script.
Test scenario (failing)
LAYOUT:
<?= $this->doctype('XHTML1_STRICT') ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?= $this->headTitle() ?> <?= $this->headMeta() ?> <?= $this->headScript() ?> <?= $this->headLink() ?> <?= $this->headStyle() ?> </head> <body> <?= $this->layout()->content ?> <h2> layout content </h2> <?= $this->glow('My Account') ?> <?= $this->inlineScript() ?> </body> </html>
VIEW SCRIPT:
<h2> action content </h2>
Test scenario (working):
LAYOUT:
<?= $this->doctype('XHTML1_STRICT') ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?= $this->headTitle() ?> <?= $this->headMeta() ?> <?= $this->headScript() ?> <?= $this->headLink() ?> <?= $this->headStyle() ?> </head> <body> <?= $this->layout()->content ?> <h2> layout content </h2> <?= $this->glow('My Account') ?> <?= $this->inlineScript() ?> </body> </html>
VIEW SCRIPT:
<h2> action content </h2>
<?= $this->glow('My Account') ?>
Neither is it possible to load headscripts or headlinks appended by a view helper called in a partial, while this kinda defeats the purpose of 'on demand loading' of files
Funny thing is, this DOES work:
<?= $this->doctype('XHTML1_STRICT') ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?= $this->glow('My Account') ?>
<?= $this->headTitle() ?>
<?= $this->headMeta() ?>
<?= $this->headScript() ?>
<?= $this->headLink() ?>
<?= $this->headStyle() ?>
</head>
<body>
<?= $this->layout()->content ?>
<h2> layout content </h2>
<?= $this->inlineScript() ?>
</body>
</html>
Meaning if you append script before calling <?= $this->headScript() ?>, they will be appended. Again, this defeats the purpose (as you're not going to write the html contents in your HEAD section off course...)