2013-04-23 4 views
1

Я пытаюсь получить доступ к моей странице 'login', и я использую 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.

И когда я пытаюсь доступ к нему, с URL-адресом http://localhost/dist/login, я просто получаю '404 Страница не найдена: запрошенная вами страница не найдена.'

Я не понимаю, почему. Все готово.

+0

Что делать, если вы пробовали URL: 'http: // localhost/dist/index.php/login' – ekims

ответ

0

Вы пробовали отладить его?
Если у вас нет определенных маршрутов, вы все равно получите ошибку 404?
Я бы поспорил, что проблема в том, что вы маршрутизируете путь к себе, но я точно не знаю.

Выньте все маршруты и убедитесь, что путь работает. Затем добавьте по одному, пока он не перестанет работать.

+0

Я только что нашел проблему с ответом ekims. Я просто должен написать url: http: //localhost/dist/index.php/login, может быть, потому, что я не удаляю index.php на .htaccess. Спасибо за Ваш ответ. – Lilrom

1

Попробуйте обратиться к URL-адресу http://localhost/dist/index.php/login. Не похоже, что вы удалили index.php в файле конфигурации. Here is how to do that.

+0

Я пробую этот url, и это правильно. Но у меня есть в моей .htaccess, в папке приложения: 'RewriteEngine на RewriteBase/ # Скрыть приложения и системные каталоги перенаправляя запрос на index.php RewriteRule^(приложение | системы) index.php/$ 1 [L] RewriteCond% {REQUEST_FILENAME}! -f RewriteCond% {REQUEST_FILENAME}! -d RewriteRule^(. *) $ index.php/$ 1 [QSA, L] ' Но я 404, если я пытаюсь получить доступ к URL-адресу http: // localhost/dist/login'. – Lilrom

+0

В файле 'application/config/config.php' вы изменили' $ config ['index_page'] = ''; 'на пустую строку? – ekims

+0

Да! В моих файлах config.php у меня есть $ config ['index_page'] = ''; Поэтому я не понимаю. – Lilrom