【问题标题】:Flash message show continuously in code-igniter闪烁消息在代码点火器中持续显示
【发布时间】:2017-11-23 07:25:54
【问题描述】:

flash 消息在打开另一个页面时不断显示我们完成该事件显示该事件消息

控制器

$this->session->set_flashdata('msg', '<div class="alert alert-danger  text-center"> Some error occured... Try Later!!!...</div>');
redirect('Admin/add_customer');

查看

<h4><?php echo $this->session->flashdata('msg');?></h4>

并且我们在这个事件之后采取另一个页面在那个页面中显示相同的消息,刷新两次或更多时间将隐藏在新页面中, 有什么办法可以解决这个问题?

【问题讨论】:

  • Flashdata 将只对下一个服务器请求可用,然后自动清除。

标签: php codeigniter flash-message


【解决方案1】:

通常 flash-data 仅可用于下一个服务器请求,然后自动清除。因此,如果您刷新页面并且如果它s not cached, flash message should disappear.How ever if its 不起作用,您可以清除与视图中的消息相关的会话数据(不鼓励)

<h4><?php echo $this->session->flashdata('msg');
unset($_SESSION['msg']);
?></h4>

【讨论】:

    【解决方案2】:

    您可以尝试该类型它是否正常工作,并且我在所有 CI 项目中都使用了该代码。

    控制器:

    if($query){
          $this->session->set_flashdata('success', 'Sucessful added store');
          redirect($this->redirect);
        }
        else{
          $this->session->set_flashdata('error', 'Something is wrong. Error!!');
           redirect($this->redirect);
        }
    

    查看:

    <?php if ($this->session->flashdata('success')) { ?>
    
            <div class="alert alert-success">
              <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <strong><?php echo $this->session->flashdata('success'); ?></strong>
            </div>
    
    <?php } ?>
    
    <?php if ($this->session->flashdata('error')) { ?>
    
            <div class="alert alert-danger">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <strong><?php echo $this->session->flashdata('error'); ?></strong>
            </div>
    
    <?php } ?>
    

    【讨论】:

      【解决方案3】:
      session->flashdata('success')) { ?>
          <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
              <strong><?php echo $this->session->flashdata('success'); ?></strong>
          </div>
      
      session->flashdata('error')) { ?>
          <div class="alert alert-danger">
              <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
              <strong><?php echo $this->session->flashdata('error'); ?></strong>
          </div>
      

      【讨论】:

      • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。 proper explanation 将通过展示为什么这是解决问题的好方法,并使其对有其他类似问题的未来读者更有用,从而大大提高其长期价值。请edit您的回答添加一些解释,包括您所做的假设。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2014-10-23
      • 2018-06-14
      • 2019-10-19
      • 1970-01-01
      相关资源
      最近更新 更多