【问题标题】:Image link with $confirmMessage alert in Cakephp HTMLhelper - possible?Cakephp HTMLhelper中带有$confirmMessage警报的图像链接-可能吗?
【发布时间】:2012-01-09 19:46:05
【问题描述】:

是否可以使用 CakePHP 中的 html 帮助程序创建一个带有弹出警报 [$confirmMessage] 的链接的图像?

这是我当前的文本链接:

$this->Html->link('Clear list', array('controller' => 'items', 'action' => 'clearlist', $model['Model']['id']), array(), 'Clear list?')

图像助手如何使用链接创建图像:

echo $this->Html->image("recipes/6.jpg", array( "alt" => "Brownies", 'url' => array('controller' => 'recipes', 'action' => 'view', 6)));

但是,这仅允许 htmlattributes 数组作为链接的参数。

$confirmMessage 警报不是 html 属性吗?

这是我试过的代码:

echo $this->Html->link($this->Html->image("clearall.png", array("alt" => "Clear list")), array('controller' => 'items', 'action' => 'clearlist', $model['Model']['id']), array(), 'Clear list?');

然而,这段代码为我的 img 打印了正确的 html 作为文本:

<img src="/img/clearall.png" alt="Clear list" />

在这种情况下我必须放弃 htmlhelper 吗?

【问题讨论】:

    标签: cakephp hyperlink html-helper image


    【解决方案1】:

    CakePHP 确实使用 Html 助手来做到这一点,你真的很接近!

    <?php echo $this->Html->link($this->Html->image('clearall.png', array(
                                                        'alt' => 'Clear list')
                                                   ), array(
                                                        'controller' => 'items',
                                                        'action' => 'clearlist',
                                                        $model['Model']['id']
                                                   ), array(
                                                        'escape' => false,
                                                        'confirm' => 'Clear list?'
                                                   )); ?>
    

    如果没有助手,你也可以这样做:

    <a href="/items/clearlist/<?php echo $model['Model']['id']; ?>"
       onclick="return confirm(&#039;Clear list?&#039;);">
        <img src="/img/clearall.png" alt="Clear list" />
    </a>
    

    感谢 ADmad 和 rtconner 在 IRC 中向我展示了这一点。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    相关资源
    最近更新 更多