1

我正在尝试访问我的页面“登录”,并且正在使用 Codeingiter。

我也在使用 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

我的本地网址是:http://localhost/dist.

当我尝试使用 URL 访问它时http://localhost/dist/login,我只会得到“404 Page Not Found:找不到您请求的页面。”

我不明白为什么。一切准备就绪。

4

2 回答 2

1

尝试访问 url http://localhost/dist/index.php/login。您似乎没有删除index.php配置文件中的 。下面是如何做到这一点

于 2013-04-23T13:26:41.703 回答
0

你试过调试它吗?
如果您没有定义任何路由,您还会收到 404 错误吗?
我敢打赌,这个问题是因为你正在路由一条到自己的路径,但我不确定。

取出所有路线并确保路径有效。然后,一次添加一个,直到它停止工作。

于 2013-04-23T13:19:14.893 回答