2013-04-23 150 views
1

我正在嘗試訪問我的頁面「登錄」,並使用了Codeingiter。404在Codeigniter上找不到

我也使用TAL php的模板。

我剛纔定義我的路線是這樣的:

$route['default_controller'] = "site"; 
$route['404_override']  = ''; 

$route['login'] = 'login'; 
$route['signup'] = 'login'; 
$route['success'] = 'login'; 

這裏是我的 '登錄' 控制器:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Login extends CI_controller{ 

public function __construct(){ 

    parent::__construct(); 
    $this->tal->setOutputMode(PHPTAL::HTML5); 
     if($this->session->userdata('loggedIn') == true){ 
      $this->tal->template = 'admin'; 
      $this->tal->login = true; 
     }else{ 
      $this->tal->template = 'main'; 
      $this->tal->login = false;    
     } 
    $this->load->model('membership_model'); 
} 

public function index(){ 

    $requestPage = $this->uri->segment(1); 

    switch($requestPage){ 
     case 'login': 
      $this->tal->title = 'Connexion'; 
      $this->tal->display('login.php'); 

     break; 
     case 'signup': 
      $this->tal->title = 'Inscription'; 
      $this->tal->display('signup.php'); 
      $this->createMember(); 
     break; 
     case 'success': 
      $this->tal->title = 'Inscription validée!'; 
      $this->tal->display('messagePage/signupSuccess.php'); 
     break; 
    } 
} 

function validateCredentials(){ 

    $query = $this->membership_model->validate(); 
     if($query){ 
      $userdata = array(
       'username' => $this->input->post('username'), 
       'password' => md5($this->input->post('password')), 
       'loggedIn' => true 
      ); 
      $this->session->set_userdata($userdata); 
      redirect('backoffice/profile/#');  
     } 
    $this->index(); 
} 

function createMember(){ 

    $this->load->library('form_validation'); 
    $this->form_validation->set_rules('name', 'Nom', 'trim|required'); 
    $this->form_validation->set_rules('forename', 'Prénom', 'trim|required'); 
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); 
    $this->form_validation->set_rules('adress', 'Adresse', 'trim|required'); 
    $this->form_validation->set_rules('zipcode', 'Code Postal', 'trim|is_natural|required'); 
    $this->form_validation->set_rules('city', 'Ville', 'trim|required'); 
    $this->form_validation->set_rules('country', 'Pays', 'trim|required'); 
    $this->form_validation->set_rules('username', 'Pseudo', 'trim|required|callback_usernameCheck'); 
    $this->form_validation->set_rules('password', 'Mot de passe', 'trim|required|min_length[4]|max_length[32]'); 
    $this->form_validation->set_rules('password2', 'Confirmation du mot de passe', 'trim|required|matches[password]'); 
    $this->form_validation->set_rules('captcha', 'Captcha'); 

    $data = array(
     'firstname'  => $this->input->post('name'), 
     'forename'  => $this->input->post('forename'), 
     'username'  => $this->input->post('username'), 
     'email'   => $this->input->post('email'), 
     'adress'   => $this->input->post('adress'), 
     'zipcode'  => $this->input->post('zipcode'), 
     'city'   => $this->input->post('city'), 
     'country'  => $this->input->post('country'), 
     'password'  => $this->input->post('password'), 
     'passwordHashed' => md5($this->input->post('password')) 
    ); 

    if($this->form_validation->run() == false){} 
    else{ 
     $result = $this->membership_model->usernameCheck(); 
     var_dump($result); 
     switch($result){ 
      case false:echo 'false'; 
       $this->form_validation->set_message('', 'Désolé mais ce nom d\'utilisateur et/ou cet email sont déjà pris'); 
      break; 
      case true:echo 'true'; 
       $this->membership_model->createMember($data); 
       redirect('success'); 
      break; 
     } 
    } 
} 

function logout(){ 
    $this->session->sess_destroy(); 
    redirect('/'); 
} 

}//this ends class 

我的本地URL是:http://localhost/dist.

當我嘗試訪問它,與網址http://localhost/dist/login,我只是'404頁面找不到:您找不到頁面。'

我不明白爲什麼。一切都準備好了。

+0

如果你試過url:'http:// localhost/dist/index.php/login' – ekims 2013-04-23 13:20:01

回答

0

你試過調試嗎?
如果您沒有定義任何路由,您是否仍然遇到404錯誤?
我敢打賭,這個問題是因爲你路由到自己的路徑,但我不知道肯定。

取出所有路線並確保路徑有效。然後,一次添加一個,直到停止工作。

+0

我剛剛發現了問題,並帶有ekims的答案。我有必要寫網址:http://localhost/dist/index.php/login,也許是因爲我沒有刪除.htaccess上的index.php。感謝您的回答。 – Lilrom 2013-04-23 13:23:54

1

嘗試訪問url http://localhost/dist/index.php/login。它似乎沒有刪除配置文件中的index.phpHere is how to do that

+0

我正在嘗試這個網址,沒錯。但是我在我的.htaccess,在該文件夾的應用程序: '上 RewriteBase/ #RewriteEngine敘述隱藏通過重定向到index.php 重寫規則^請求的應用程序和系統目錄(應用程序|系統)1的index.php/$ [L] 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 重寫規則^(。*)$的index.php/$ 1 [QSA,L]' 但是,我的404錯誤,如果我嘗試訪問URL'http:// localhost/dist/login'。 – Lilrom 2013-04-23 13:29:29

+0

在'application/config/config.php'文件中,您是否已將'$ config ['index_page'] ='';'更改爲空字符串? – ekims 2013-04-23 13:32:20

+0

是的!在我的config.php文件中,我有$ config ['index_page'] ='';所以,這就是爲什麼我不明白。 – Lilrom 2013-04-23 13:32:55