2016-01-24 77 views
0

我需要你的幫助。我有一個編輯表單,在成功編輯記錄後,它將重定向到另一個頁面,並自動顯示從set_flashdata傳遞的消息的模式。如果set_flashdata不爲空CodeIgniter會自動顯示模態

這是我到目前爲止已經試過:

查看

<button type="button" class="btn btn-primary btn-success" data-toggle="modal" data-target="#modalSuccess"> 
             Modal Success 
            </button> 

            <div class="modal fade modal-success" id="modalSuccess" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
             <div class="modal-dialog"> 
              <div class="modal-content"> 
               <div class="modal-header"> 
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
                <h4 class="modal-title" id="myModalLabel">Modal Success</h4> 
               </div> 
               <div class="modal-body"> 
                <?php echo $message;?> 
               </div> 
               <div class="modal-footer"> 
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
                <button type="button" class="btn btn-success">OK</button> 
               </div> 
              </div> 
             </div> 
            </div> 

控制器:

// check to see if we are updating the user 
      if($this->ion_auth->update($user->id, $data)) 
      { 
       // redirect them back to the admin page if admin, or to the base url if non admin 
       $this->session->set_flashdata('message', $this->ion_auth->messages()); 
       if ($this->ion_auth->is_admin()) 
       { 
        redirect('auth/profile/', 'refresh'); 
       } 
       else 
       { 
        redirect('auth/profile/, 'refresh'); 
       } 

      } 

我不知道如何自動模式的火一旦從set_flashdata接收消息。有任何想法嗎?我很樂意欣賞它。謝謝!

回答

0

Codeigniter會話設置閃存數據只有在重定向時才起作用。

目前已設置的閃光數據輸出重定向

的側,因爲你使用的刷新與重定向它會清除它。

if($this->ion_auth->update($user->id, $data)) { 

// redirect them back to the admin page if admin, or to the base url if non admin 


if ($this->ion_auth->is_admin()) { 

    $this->session->set_flashdata('message', $this->ion_auth->messages()); 
    redirect('auth/profile'); 

} else { 

    $this->session->set_flashdata('message', $this->ion_auth->messages()); 
    redirect('auth/profile'); 
} 


} 

上查看呼應flashdata

<?php echo $this->session->flashdata('message');?> 
0

在視圖文件,你應該把:

<?php if ($this->session->flashdata('message')):?> 
<script> 
    $('#modalSuccess').modal('show'); 
</script> 
<?php endif;?> 

確保已jQuery.jsbootstrap.js之前加載。