0

在下面的 codeigniter 代码中,我放置了控制器和视图部分。现在,如果一个非活动用户尝试登录该帐户,它应该与登录表单一起显示在活动用户中。在我的情况下,该消息在没有登录的情况下显示,最后登录表单消失。控制器:

function index()
    {
        $data['main_content'] = 'login_form';
        $this->load->view('includes/template', $data);      
    }
    function inactive()
    {
    echo"<script>alert('In active user');</script>";
    }

    function validate_credentials()
    {       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            if($query->num_rows()>0){
             $status = $query->row()->account_status;}
            else {
             $status = ''; }
            if($status == 'active')
            {
               $this->session->set_userdata($data);
               redirect('site1/members_area');
            }
            else //Account In active
            {  $this->inactive();  }
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }   

看法:

<?php $this->load->view('includes/header'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style1.css"  />
<div id="login_form">

    <h1>Login!</h1>
    <?php 
    echo form_open('login/validate_credentials');
    echo form_input('username', 'Username');
    echo form_password('password', 'Password');
    echo form_submit('submit', 'Login');
    echo anchor('login/signup', 'Create Account');
    echo form_close();
    ?>

</div><!-- end login_form-->


<?php $this->load->view('includes/footer'); ?>
4

3 回答 3

1

我看不到你在控制器中的哪里调用了你的视图文件inactive()

  function inactive()
    {
    echo"<script>alert('In active user');</script>";
     $this->load->view('Your view with login form'); // this part
    }
于 2013-11-14T11:32:08.233 回答
0

这里最明显(可能)的错误是您没有将发布的数据传递给$this->membership_model->validate();. 由于您没有将代码发布到该函数,我不能 100% 确定,但我敢打赌这是问题所在。信息未传递,因此$query变量设置不正确,因此显示错误。

于 2013-11-14T14:16:22.363 回答
0

你为什么不试试这个:

function index($inactive_login = FALSE) {
    $data['inactive_login'] = $inactive_login;
    $data['main_content'] = 'login_form';
    $this->load->view('includes/template', $data);
}

function validate_credentials() {       
    $this->load->model('membership_model');
    $query = $this->membership_model->validate();

    if($query) // if the user's credentials validated...
    {
        $data = array(
            'username' => $this->input->post('username'),
            'is_logged_in' => true
        );
        if($query->num_rows()>0){
         $status = $query->row()->account_status;}
        else {
         $status = ''; }
        if($status == 'active')
        {
           $this->session->set_userdata($data);
           redirect('site1/members_area');
        }
        else //Account In active
        { 
            $inactive_login = TRUE;
            $this->index($inactive_login);  
        }
    }
    else // incorrect username or password
    {
        $this->index();
    }
}

看法:

<?php $this->load->view('includes/header'); ?>
<?php 
    if($inactive_login){
        echo "<script>alert('In active user');</script>";
    }
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style1.css"  />
<div id="login_form">

<h1>Login!</h1>
<?php 
    echo form_open('login/validate_credentials');
    echo form_input('username', 'Username');
    echo form_password('password', 'Password');
    echo form_submit('submit', 'Login');
    echo anchor('login/signup', 'Create Account');
    echo form_close();
?>
</div><!-- end login_form-->
<?php $this->load->view('includes/footer'); ?>
于 2013-12-12T18:12:13.820 回答