CodeIgniter路由不起作用,抛出404错误

时间:2015-09-19 09:14:09

标签: php codeigniter

Enter image description here

我是CodeIgniter的新手。我正在尝试加载路线,但它无法正常工作。这是我的代码:

ROUTE:

$route['default_controller'] = 'Welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

$route['register'] = 'Register_controller';  //  Not  working
$route['register/thankyou'] = 'Register_controller';  //  Not  working

注册控制器:

class Register_controller extends CI_Controller {

    public function index()
    {
        $this->load->view('register');
    }

    public function thankyou()
    {
        $this->load->view('thankyou');
    }
}

查看:

  

我在视图部分

上有register.php和thankyou.php页面

为什么不起作用?

它正在显示CodeIgniter 404页面。

1 个答案:

答案 0 :(得分:1)

我认为您应该在控制器中添加方法名称,如下所示。

$route['register'] = 'Register_controller/index'; 
$route['register/thankyou'] = 'Register_controller/thankyou';

$route['register'] = 'register_controller/index'; 
$route['register/thankyou'] = 'register_controller/thankyou';