Jor*_*enB 8 jquery zend-framework fisheye
我正在使用Zend_Navigation(对框架的加法,btw)来构建我的菜单,然后它应该在页面中呈现(显而易见).我首先在控制器中的某处设置容器:
// $pages is the array containing all page information
$nav = new Zend_Navigation($pages);
$this->view->navigation($nav);
Run Code Online (Sandbox Code Playgroud)
然后,在布局中,它呈现如下:
echo $this->navigation()->menu();
Run Code Online (Sandbox Code Playgroud)
哪作得很好.现在:我希望菜单的呈现方式略有不同.我正在构建的页面使用jQuery Fisheye-plugin来构建类似Mac的Dock菜单.但是,这个插件需要一个特定的标记......
实际上,它需要一个<a>包含<img>(用于图标)和<span>(用于工具提示)的元素列表.标准的Menu视图助手将所有内容呈现在无序列表中(逻辑上),并将'label'参数作为链接文本.
似乎传递给'label'参数的内容在渲染之前被转义,因此插入html对我没有任何好处.此外,Fisheye通常似乎不会将其包含在<li>标签中的项目包含在整个事物中<ul></ul>,而只是一个单级的<a>元素列表.
我正在考虑为dock编写一个自定义视图助手,它可以负责插入<img>和<span>,但是我很难将自定义视图助手附加到Navigation类.我只是无法弄清楚在哪里放置它以及以何种方式,即使我的所有其他自定义类(模型等)都由自动加载器甜蜜地照顾.有什么想法吗?
然后,即使我可以让这个视图助手工作,我仍然留下HTML无序列表 - 我知道我也可以使用自定义视图助手丢失那个,但我一直是包含主要的粉丝的粉丝为了语义,列表中的导航菜单.
如果有人能帮助我一点点,我会非常感激.如果Fisheye不打算与<ul>ss合作,那就太糟糕了......在这种情况下,是否有充分理由完全失去Zend_Navigation?
typ*_*ror 24
我还没有看到制作自定义渲染器的方法.这是我最终做的事情:
首先,不是渲染默认的menu()调用,而是创建一个部分渲染到:
// menu.phtml is partial, cms is module
$partial = array('menu.phtml', 'cms');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
Run Code Online (Sandbox Code Playgroud)
然后(从文档中),您可以创建一个"自定义"渲染,如下所示:
// -- inside menu.phtml
foreach ($this->container as $page)
{
// this just prints a "<a>" or "<span>" tag
// depending on whether the page has a uri
echo $this->menu()->htmlify($page), PHP_EOL;
}
Run Code Online (Sandbox Code Playgroud)
我最终用这个脚本制作了我原来拥有的东西(带有一级子菜单的菜单):
// -- another menu.phtml
<ul class="navigation">
<?php
$html = array();
foreach ($this->container as $page)
{
$html[] = "<li>";
$html[] = $this->menu()->htmlify($page) . PHP_EOL;
if (!empty($page->pages))
{
$html[] = "<ul>";
foreach ($page->pages as $subpage)
{
$html[] = "<li>";
if ($href = $subpage->getHref()) $html[] = "<a href=\"{$href}\">";
else $html[] = "<span>";
$html[] = "<img src=\"/ui/cms/img/icons/edit.png\" alt=\"\"/>";
$html[] = $subpage->getLabel();
if ($href) $html[] = "</a>";
else $html[] = "</span>";
$html[] = "</li>";
}
$html[] = "</ul>";
}
$html[] = "</li>";
}
echo join(PHP_EOL, $html);
?>
</ul>
Run Code Online (Sandbox Code Playgroud)
您只需更改部分中的标记,然后在其中添加图像/图标即可.
抱歉,上一篇文章中的格式问题
要添加自定义帮助程序,请在引导程序中执行以下操作:
protected function _initNavigation()
{
$this->bootstrap('view'); // make sure we have a view
$view = $this->getResource('view'); // get the view resource
$config = new Zend_Config_Xml(APPLICATION_ROOT . '/config/navigation.xml','nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
// Tell Zend were it can find your custom helpers and what
// the prefix is going to be.
$view->addHelperPath(
APPLICATION_ROOT . '/library/MyApp/View/Helper/Navigation',
'MyApp_View_Helper_'
);
}
Run Code Online (Sandbox Code Playgroud)
接下来创建自定义视图助手并将其放在"addHelperPath"路径中.根据您的要求,您需要至少实现自己的htmlify功能.以Zend/View/Help/Navigation/Menu.php为例.
class MyApp_View_Helper_MyMenu extends Zend_View_Helper_Navigation_Menu
{
public function myMenu(Zend_Navigation_Container $container = null)
{
if (null !== $container) {
$this->setContainer($container);
}
return $this;
}
protected function htmlify(Zend_Navigation_Page $page )
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
接下来,在你的phtml脚本中:
<?php echo $this->navigation()->myMenu()->setMaxDepth(0); ?>
Run Code Online (Sandbox Code Playgroud)
要不就
<?php echo $this->navigation()->myMenu(); ?>
Run Code Online (Sandbox Code Playgroud)
现在,如果要将自己的自定义属性添加到生成的HTML中,可以将它们添加到导航ini或xml文件中.例如:
<home>
<label>Home</label>
<uri>/</uri>
<img>
<src>/images/MyIcon.gif</src>
<img>
</home>
Run Code Online (Sandbox Code Playgroud)
自定义xml标记<img>将存储为导航页面的属性,并且可以像下面这样获取:
foreach ($iterator as $page) {
...
$properties = new Zend_Config($page->GetCustomProperties());
$myPicture = $properties->img->src;
...
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.彼得
| 归档时间: |
|
| 查看次数: |
17368 次 |
| 最近记录: |