0

我正在使用 setFlash 函数在页面顶部显示一条消息,但我想更改它显示多长时间(目前在 .js 文件中它是 3000,但我希望它显示 20 秒而不是 3 )

有没有办法对特定 setFlash 的页面停留时间进行编码?而不是更改网站范围内的 setFlash 默认值?

这是我在控制器页面中的代码。

 $this->Session->setFlash(__l('There is not enough in escrow to close the project ') , 'default', null, 'error');
            $this->redirect(array(
                'controller' => 'escrow_accounts',
                'action' => 'add',
                'project' => $escrowAccount['Project']['id']
            ));
4

3 回答 3

0

您需要为 Flash 消息创建自定义模板。例如:

// location /app/View/Elements/flash_message.ctp

<div id="flashMessage" data-timeout="<?php echo $timeout;?>"> 
    <?php echo $message; ?> 
</div>

然后通过设置 Session flash 消息来使用这个自定义模板:

$this->Session->setFlash(
    __l('There is not enough in escrow to close the project '), 
    'flash_message', 
    array('timeout' => 3000), 'error');

现在,您需要在 javascript 中获取超时参数。我假设,你正在使用 jQuery:

var interval = $("#flashMessage").attr("data-timeout");

就是这样,您可以根据需要设置自定义超时。

于 2013-10-04T11:33:56.320 回答
0

让我举一个设置消息暂停的例子:这会给你 30 秒。

$this->flash('Your message', array('action' => 'index'), 30);
于 2013-10-04T11:27:10.803 回答
0

Flash 消息可以有第四个参数,'key',然后您可以将其用作 css 和 js 的句柄。在这里阅读:http: //book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages

因此,您将拥有一个名为“long-flash”或类似的键,只需将这些特定的 Flash 消息设置为显示 20 秒。

于 2013-10-04T11:26:18.150 回答