如何在控制器消息中添加链接?

时间:2014-11-13 06:32:27

标签: cakephp

我设计了一个在线购物网站,其中包含了"比较产品"选项。

因此,在点击比较按钮后,会出现一个可忽略的警告框,其中包含消息,"产品已成功添加以进行比较"将会显示。但是,我现在需要为用户提供一个链接,让他们点击并直接进入比较页面。

喜欢"产品成功添加进行比较。您可以点击此处查看"。

但是,我不知道如何添加链接。

我使用的代码是,

$this->Session->setFlash(__('Product Successfully Added to Compare '), 'success');

请告诉我如何添加信息链接。

4 个答案:

答案 0 :(得分:1)

我刚刚在其他链接中找到了这个并且工作正常。为您的努力和答案做好准备。

试试这个。

1)在session_flash_link.ctp中创建了新元素app/views/elements

2)在session_flash_link.ctp中添加了以下代码:

<div id="flashMessage" class="message"> 
<?php
echo $message;
echo $this->Html->link($link_text, $link_url, array("escape" => false));
?>
</div>

3)控制器中的代码:

$this->Session->setFlash("Shop has been successfully saved. ", "session_flash_link", array(
      "link_text" => "Return to Shop Management &raquo;",
      "link_url" => array(
        "controller" => "shops",
        "action" => "manage",
        "admin" => true
      )
 ));

答案 1 :(得分:0)

使用以下内容:

// access the html helper
$Html = (new View($this))->loadHelper('Html');
// use it to generate a link    
$resend = $Html->link(__('resend'), array(
    'controller' => 'users',
    'action' => 'resend',
));
// sprintf to insert the link to your standard message text!
$this->Session->setFlash(sprintf(_("Product Successfully Added to Compare."), $resend));

答案 2 :(得分:0)

更简单方法,甚至不使用帮助

    $this->Session->setFlash('Page not found <a href="'. Router::url(array('controller' => 'users', 'action' => 'login')) .'"> login here</a>', 'error');

答案 3 :(得分:0)

只做

$this->Session->setFlash('Product Successfully Added to Compare <a href="link here">click here</a>');

希望有所帮助

相关问题