注册后无法将闪存数据用于页面

Cannot get flash data to work to a page after register

所以我试图从登录屏幕转到管理屏幕,我设置了闪存数据,这样我就可以告诉用户他们是否登录,并检查是否有多个用户或密码错误会显示对不起你没有登录。 所以这是我的控制器。

public function insertInformation(){
                $this->load->helper('form');
                $this->load->library('form_validation');

                $this->form_validation->set_rules('name', 'Name', 'required');
                $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_check_if_email_exists');
                $this->form_validation->set_rules('phone', 'Phone', 'required');
                $this->form_validation->set_rules('password', 'Password', 'required|min_length[4]|max_length[32]');
                $this->form_validation->set_rules('password_confirm', 'Password Confirm', 'required|matches[password]');


                if ($this->form_validation->run() == FALSE){
                $this->load->view('header_view');
                $this->load->view('login_view');
                $this->load->view('footer_view');
                }else{

                    $data =  array(
                    'name' => $this->input->post('name'),
                    'email' => $this->input->post('email'),
                    'phone' => $this->input->post('phone'),
                    'password' => $this->input->post('password')

                );


                    $this->load->model('main_page');
                  $user_id = $this->main_page->storeRegisterInfo($data);

                    if($user_id){
                        $user_data = array(
                            'user_id' =>$user_id,
                            'name'=> $name,
                            'logged_in' => true
                        );

                        $this->session->set_userdata($user_data);
                        $this->session->set_flashdata('login_sucess','you are now loggedin');
                        $this->Admin();
                    }else{
                        $this->session->set_flashdata('login_failed','you are not loggedin');
                        $this->login();
                    }

                }




        }

这是插入数据的模态,我不确定如何检查用户 ID 是否存在以及检查用户是否有有效的登录信息。

public function storeRegisterInfo($data){

            $insert = $this->db->insert('new_users',$data);
            $result = $this->db->get('new_users');
            if($result ->num_rows()== 1){
                return $result->row(0)->id;
            }else{
                return false;
            }


        }

最后,登录功能中的视图是这样的。基本上这是一个注册表格,但我到处都写错了登录,所以请不要混淆。

<p class="bg-danger">

<?php if($this->session->flashdata('login_failed')): ?>
<?php echo $this->session->flashdata('login_failed'); ?>

<?php endif; ?>


</p>

管理员也一样。

<p class="bg-success">

<?php if($this->session->flashdata('login_success')): ?>
<?php echo $this->session->flashdata('login_success'); ?>

<?php endif; ?>


</p>


<h1>hello</h1>

所以我无法让闪存数据工作,也无法识别用户是否已经存在或输入了错误的密码。

设置 flash 数据后重定向页面

redirect('controllerNmae/Method');

编辑 01

正在查看

<?php
    if(!empty($this->session->flashdata('login_sucess')))
    {
        echo $this->session->flashdata('login_sucess');
    }

    if(!empty($this->session->flashdata('login_failed')))
    {
        echo $this->session->flashdata('login_failed');
    }
?>

<?php
    if(!empty($this->session->flashdata('login_sucess')))
    {
        ?>
        <script>
            alert('<?php $this->session->flashdata('login_sucess'); ?>');
        </script>
    <?
    }

     if(!empty($this->session->flashdata('login_failed')))
    {
        ?>
        <script>
            alert('<?php $this->session->flashdata('login_failed'); ?>');
        </script>
    <?
    }
?>

Tip: Use this library alertify JS. Its gives nice user experience
Ex

<script>
   alertify.success('<?php $this->session->flashdata('login_sucess'); ?>');
</script>