控制器/方法路由上的CodeIgniter 404错误

时间:2014-01-18 20:08:55

标签: php .htaccess codeigniter

我现在正面临一个小问题,使用CodeIgniter ......

我有以下文件:

applications/controllers/home/entretiens.php

看起来像这样:

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

class Entretiens extends CI_Controller
{
    public function index()
    {
        if($this->session->userdata('logged_in'))
        {
             $data['page'] = "entretiens";
             $session_data = $this->session->userdata('logged_in');
             $data['prenom'] = $session_data['prenom'];
             $this->load->model("Entretiens_model");
             $data['entretiens'] = $this->Entretiens_model->getAllEntretiens($session_data['id']);
             $data['main_content'] = 'home/entretiens_view.php';
             $this->load->template('entretiens_view', $data);
        }
        else
        {
            //If no session, redirect to login page
            redirect('home/login', 'refresh');
        }
    }

    public function ajouter()
    {
        echo 'Test';
    }
}

?>

如果我使用我的浏览器:myurl/entretiens我得到了正确的页面(控制器“entretiens”的索引方法),但如果我转到myurl/entretiens/ajouter,我得到的是404笨

这是我的路线档案:

$route['default_controller'] = "home/index_controller";
$route['login'] = "home/login_controller";
$route['user'] = "home/user_controller";
$route['entretiens'] = "home/entretiens";
$route['404_override'] = '';

config.php(好吧,有趣的部分):

$config['base_url'] = 'http://dev.hinsolite.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

我的.htaccess

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

(这个问题出现在所有控制者身上,而不仅仅是entretiens ......

1 个答案:

答案 0 :(得分:1)

更改routes.php中的相关行,如下所示:

$route["entretiens(.*)"] = "home/entretiens$1";

这视为通配符,entretiens之后的所有内容都会传递给home/entretiens