在 Codeigniter 中重定向后显示 Flash 消息
在你的控制器中设置这个
<?php
public function change_password(){
if($this->input->post('submit')){
$change = $this->common_register->change_password();
if($change == true){
$messge = array('message' => 'Password chnage successfully','class' => 'alert alert-success fade in');
$this->session->set_flashdata('item', $messge);
}else{
$messge = array('message' => 'Wrong password enter','class' => 'alert alert-danger fade in');
$this->session->set_flashdata('item',$messge );
}
$this->session->keep_flashdata('item',$messge);
redirect('controllername/methodname','refresh');
}
?>
In Your View File Set this
<script type="application/javascript">
/** After windod Load */
$(window).bind("load", function() {
window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 4000);
});
</script>
<?php
if($this->session->flashdata('item')) {
$message = $this->session->flashdata('item');
?>
<div class="<?php echo $message['class'] ?>"><?php echo $message['message']; ?>
</div>
<?php
}
?>
请检查以下链接以在 Codeigniter 中重定向后显示闪烁消息