【问题标题】:CodeIgniter automatically display modal if set_flashdata is not empty如果 set_flashdata 不为空,CodeIgniter 会自动显示模态
【发布时间】:2016-01-24 16:46:11
【问题描述】:

我需要你的帮助。我有一个编辑表单,在成功编辑记录后,它将重定向到另一个页面并自动显示带有从 set_flashdata 传递的消息的模式。

这是我迄今为止尝试过的:

查看

 <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 的消息后自动触发模态。有任何想法吗?我很乐意欣赏它。谢谢!

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    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');?>
    

    【讨论】:

      【解决方案2】:

      在你的视图文件中你应该放:

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

      确保您之前已加载 jQuery.jsbootstrap.js

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多