2015-10-20 59 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(); 
    } 
}