注册后无法使闪存数据工作到页面 [英] Cannot get flash data to work to a page after register

查看:94
本文介绍了注册后无法使闪存数据工作到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图从登录屏幕到管理屏幕,我设置闪存数据,以便我可以告诉用户,如果他们是否已登录,并还检查是否有多个用户或错误的密码,它会显示抱歉你没有登录。
这是我的控制器。

  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 $ b'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 = -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'); 






EDIT 01 / p>

查看

 < ;? 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>
< ;?
}
?>




提示:使用此库 alertify JS 。它提供了不错的用户体验

Ex

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



So I am trying to get from login screen to admin screen, and I set flash data so I can tell the users if they are logged in, and also check if there is more than one user or a wrong password it will show sorry you are not logged in. So this is my controller.

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();
                    }

                }




        }

This is the modal where the data is being inserted and I am not sure how to check if the user id exist and as well as check if the user has valid info to login.

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;
            }


        }

And lastly for the view in login function its like this. Basically this is a register form but i wrote login everywhere by mistake so please dont get confused.

<p class="bg-danger">

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

<?php endif; ?>


</p>

And similarly for the admin.

<p class="bg-success">

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

<?php endif; ?>


</p>


<h1>hello</h1>

So I cannot get the flash data to work ,and as well as cant identify if the user already exists or wrote the wrong password.

解决方案

After setting flash data redirect the page

redirect('controllerNmae/Method');


EDIT 01

In view

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

or

<?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>

这篇关于注册后无法使闪存数据工作到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆