2015-10-20 62 views
2

登录后,我显示仪表板,但URL不是“/ dashboard”,登录后显示URl显示:http://localhost/tools2/login/validate_credentialsCodeIgniter:如何在登录后查看仪表板并获取要成为/仪表板的URL

我希望它是http://localhost/tools2/dashboard当我输入这个URL时,我什么也没有显示。

这是负责的 “控制器” 一节中登录的代码:

的login.php

// 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 --> 
+1

''this - > load-> view('dashboard');'use'redirect('dashboard');''validate_credentials()'''' –

回答

1

试试这个

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