CAKEPHP:链接整个< div> [英] CAKEPHP: Linking the whole <div>

查看:38
本文介绍了CAKEPHP:链接整个< div>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Notes表中有一个特定字段的视图.

I have a having view of a specific field in Notes table.

    echo "<div id='notescover'>";
    echo "<p class='text'>"; 
    echo $viewnotes['Note']['notes']; 
    echo "</p>"; 
    echo "</div>";

并且我已将Comment链接到特定的注释URL,例如/note/view/IDofNote

And i have linked Comment to the specific note URL e.g /note/view/IDofNote

echo $this->Html->link('Comment', array( 'controller'=>'notes', 'action'=>'view',$viewnotes['Note']['id']), array('class'=> 'light_blue'));

我想删除此链接并将相同的操作链接到上面的div标签.我能够像这样在字段内链接文本

I want to remove this link and link the same action to the above div tag. I was able to link the text inside the field like this

echo $this->Html->link($viewnotes['Note']['notes'], array( 'controller'=>'notes', 'action'=>'view',$viewnotes['Note']['id']), array('class'=> 'light_blue'));

但是我希望整个盒子都被链接起来.

but i want the whole box that makes to be linked.

我该怎么做?

推荐答案

类似以下内容:

$text = '<p class="text">' . $viewnotes['Note']['notes'] . '</p>';
$div = $this->Html->div(null, $text, array('id' => 'notescover'));

echo $this->Html->link(
    $div, 
    array('controller' => 'notes', 'action' => 'view', $viewnotes['Note']['id']),
    array('class' => 'light_blue', 'escape' => false)
);

如果愿意,您还可以通过执行以下操作来进一步压缩它:

You could also compact it some more by doing this, if you prefer:

echo $this->Html->link(
    '<div id="notescover"><p class="text">' . $viewnotes['Note']['notes'] . '</p></div>', 
    array('controller' => 'notes', 'action' => 'view', $viewnotes['Note']['id']),
    array('class' => 'light_blue', 'escape' => false)
);

您可以将任何所需的内容放入 Html :: link()的第一个参数中,但是,如果您要在其中添加标记,而不仅仅是纯文本,那么包含转义=>链接上的false 属性,以避免将链接中的HTML特殊字符显示为文本.

You can put anything you like into the first parameter of Html::link(), but if you are adding markup in there, and not just plain text, it's important to include the escape => false attribute on the link, to avoid rendering the HTML special characters in your link as text.

尽管在我看来,当您使用Cake HTML帮助程序处理不简单的事情时,诸如此类的事情变得如此令人费解,甚至不值得花费时间和精力来编写这样的代码.这也使阅读代码的方式变得比所需的更为复杂,尤其是当您不得不在稍后对代码进行解密时.

Although, in my opinion, things like this become so convoluted when you use the Cake HTML helpers for anything that isn't simple, it's not even worth the time and effort to come up with code like this. It also makes reading the code way more complicated than it needs to be, especially when you have to decipher the code later down the line.

这篇关于CAKEPHP:链接整个&lt; div&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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