0

is it possible to make it happen? My view helper works fine if in a view that was a result of a controll. But I would like to have some dinamic layout, for example, to render a jquery menu according to the state I'm in.

If I call the helper from layout headScript never happens to echo the appendScript command I did inside the helper.

thanks!

4

2 回答 2

1

您在这里有几个选择。
做你想做的最简单的方法是使用inlineScript()视图助手并将其添加到引导程序中的视图或直接在布局脚本中。inlneScript() 帮助器的工作方式与 headScript() 帮助器相同,但将代码放在标记中。我有时使用inlineScript()助手将配置数据传递给音频和视频播放器。

或者,您可以使用视图助手构建自己的占位符,然后在引导程序中对其进行初始化。

这是呈现菜单的自定义占位符的简单示例:

引导程序:

 protected function _initMenus() {
        //get view object
        $view = $this->getResource('view');
        //assign the id for the menus...
        $view->mainMenuId = 4;
        $view->adminMenuId = 5;
    }

布局:

<?php
$this->layout()->adminMenu = $this->action(
        'render', 'menu', null, array('menu' => $this->adminMenuId))
?>
<div id="adminMenu">
     <!-- Render the placeholder -->
     <?php echo $this->layout()->adminMenu ?>&nbsp;
</div>

这个占位符只是使用action()助手来调用 renderAction(),但是你可以用占位符做什么几乎受限于你的想象力。

于 2012-05-11T09:39:11.597 回答
0

I don't think this is possible since if the helper is called in the layout, it will probably be calling headScript after the headScript helper has run. The only way to get it to work would be to ensure your helper is called near the top of the layout, before the headScript call.

于 2012-05-11T09:11:11.693 回答