添加HTML元素以进行导航 [英] Afdding HTML elements to zend navigation

查看:117
本文介绍了添加HTML元素以进行导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我写了一个这样的类:

So I wrote a class as such:

class Users_Navigation_Page_Notification extends Zend_Navigation_Page_Mvc{

    public function setLabel($label){
        if(substr($label, 0 , 1) == ':'){
            $label = 'Notification';
        }

        return parent::setLabel($label);
    }
}

如果我尝试类似的操作:

And if I try something like:

$label = 'Notification' . '<span>test</span>';

回显通知测试

不应该的.

如何使它呈现HTML元素?

How do I make it render HTML elements out?

推荐答案

呈现导航时,视图助手被硬编码为转义每个导航页面的标签,默认情况下使用htmlspecialchars.由于标记已被HTML实体替换,因此可以有效地禁用HTML.

When rendering navigations, the view helper is hardcoded to escape the label of each navigation page which by default uses htmlspecialchars. This would effectively disable HTML since the tags are replaced with HTML entities.

在输出导航之前,您可以尝试作弊并更改转义机制:

You can try to cheat a bit and change the escaping mechanism prior to outputting your navigation:

$view->setEscape('trim'); // will allow html and remove escaping
echo $view->navigation()->menu(); // output navigation
$view->setEscape('htmlspecialchars'); // restore escaping mechanism

在上面的代码中,如果您在视图脚本中,则可以将$view更改为$this.

In the above code, you can change $view to $this if you are within a view script.

这篇关于添加HTML元素以进行导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆