如何在CakePHP中编写HTML标签“link” [英] How to write HTML tag in CakePHP "link"

查看:100
本文介绍了如何在CakePHP中编写HTML标签“link”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CakePHP 2.2并需要编写以下代码 -

I am using the CakePHP 2.2 and need to write following code -

<a data-original-title=" Edit " data-placement="left" rel="tooltip" href="/admin/static_pages/edit/1" class="btn btn-small">
  <i class="gicon-edit"></i>
</a>

我在CakePHP中编写了以下代码 -

I have written the following code in CakePHP -

 <?php echo $this->Html->link($this->Html->tag('i', '', array('class' => 'gicon-edit')),array('controller'=>'static_pages','action'=>'edit',$page['StaticPage']['id']), array('rel'=>'tooltip','data-placement'=>'left','data-original-title'=>'Edit','class'=>'btn btn-small'));  ?>

并获得以下结果 -

and getting the following result -

<a class="btn btn-small" data-original-title="Edit" data-placement="left" rel="tooltip" href="/erudites/admin/static_pages/edit/1">&lt;i class="gicon-edit"&gt;&lt;/i&gt;</a>

如何写正确的HTML代码?

How should the correct HTML code be written?

推荐答案

说明:

添加'escape'=> ; false 选项,使它不会尝试翻译('转义')所有的html字符。

Adding the 'escape'=>false option to your link makes it so it doesn't try to translate ('escape') all your html characters.

我很少(如果EVER)发现使用CakePHP的 - > tag()有帮助。

Also, I rarely (if EVER) find it helpful to use CakePHP's ->tag(). Just write the tag - much easier (and more efficient).

示例代码

echo $this->Html->link(
   '<i class="gicon-edit"></i>',
    array(
        'controller'=>'static_pages',
        'action'=>'edit',
        $page['StaticPage']['id']
    ),
    array(
        'rel'                 => 'tooltip',
        'data-placement'      => 'left',
        'data-original-title' => 'Edit',
        'class'               => 'btn btn-small',
        'escape'              => false  //NOTICE THIS LINE ***************
    )
);

这里的详细信息: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link

PS显然,如果你愿意,代码可以是一个单行文本 - 只是为了方便阅读而在这里打破了。

PS Obviously the code could be a 1-liner if you'd rather - just broke it up here for ease of reading.

这篇关于如何在CakePHP中编写HTML标签“link”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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