Codeigniter set_flashdata无法正常工作

时间:2018-04-03 06:54:55

标签: php codeigniter

我有codeigniter flashdata的问题。每当我访问该页面时,它都会不断显示flashdata消息。

控制器:

 if ($this->form_validation->run() == true && $this
    ->Station_model>check_allowall($id , $station){

     $this->session->set_flashdata('message', lang("station_added"));
     redirect('Station');
}

else {
$this->session->set_flashdata('msg', lang('station_required'));  
$this->data['page_title'] = lang('station_move');
$this->page_construct('Station/add', $this->data);  

}

查看:

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

1 个答案:

答案 0 :(得分:0)

如果没有电台,只需重定向您的网页。

if ($this->form_validation->run() == true && $this->Station_model>check_allowall($id , $station)
{

     $this->session->set_flashdata('message', lang("station_added"));
     redirect('Station');
}

else 
{
     $this->session->set_flashdata('msg', lang('station_required')); 
     redirect('Station'); 
}

$this->data['page_title'] = lang('station_move');
$this->page_construct('Station/add', $this->data);  

在您的电台视图页面中:

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