CodeIgniter:如何在登录后查看仪表板并获取URL为/dashboard


CodeIgniter: How to view the dashboard after logging in and get the URL to be /dashboard

登录后,I显示仪表板,但URL不是"/dashboard",登录后显示的URL是:http://localhost/tools2/login/validate_credentials

我希望它是http://localhost/tools2/dashboard,当我输入这个URL时,我没有得到任何显示。

这是在"控制器"部分负责登录的代码:

login。

// Validation function: Checks if the user is in the 'users' DB and logs him in. 
function validate_credentials(){
    $this->load->helper('url');
    $email    = $this->input->post('email');
    $password = $this->input->post('password');
    $this->load->model('membership_model'); 
    $query = $this->membership_model->validate($email, $password);
    if ( $query ) {  // if the user's credentials validated...
        $data = array(
                'email' => $email, 
                'is_logged_in' => TRUE
            );
        $this->session->set_userdata($data); 
        $this->load->view('dashboard'); 
    } else {
        $this->index();
    }
}

dashboard.php

<?php
class Dashboard extends CI_Controller{
    // This is the first function to be called here. 
    function index(){
        $this->load->view('header'); 
        $this->load->view('dashboard'); 
        $this->load->view('footer'); 
    }

}

登录表单:

<div id="login_form">
    <?php if ( isset($account_created) ) { ?>
        <h3> <?php echo $account_created; ?> </h3>
    <?php } else { ?> 
        <h1>Login, Please. </h1>
    <?php } ?>
    <?php 
        echo form_open('login/validate_credentials');
        echo form_input('email', 'Email');
        echo form_password('password', '', 'placeholder="Password" class="password"');
        echo form_submit('submit', 'Login');
        echo anchor('login/signup', 'Create Account');
        echo form_close();
    ?>
    <?php echo validation_errors('<p clas="error">'); ?>
</div> <!-- END login_form -->

试试这个

function validate_credentials(){
    $this->load->helper('url');
    $email    = $this->input->post('email');
    $password = $this->input->post('password');
    $this->load->model('membership_model'); 
    $query = $this->membership_model->validate($email, $password);
    if ( $query ) {  // if the user's credentials validated...
        $data = array(
                'email' => $email, 
                'is_logged_in' => TRUE
            );
 $this->session->set_userdata($data); 
       redirect('Dashboard');
    } else {
        $this->index();
    }
}