codeigniter路由任何或数字不工作

时间:2014-11-30 21:32:15

标签: php codeigniter codeigniter-2 codeigniter-url codeigniter-routing

我的网址与http://lp.dev/sisters/adab/1类似,但当我使用(:num)(:any)获取值1时,路线无效,因为该路线为我提供了404页

路线如下

$route['default_controller'] = "frontend/home";
$route["sisters/adab/(:num)"]   = "frontend/pages/$1";  //<-- this is my issue
$route['404_override']  = 'errors/error_404';

controller:在frontend文件夹中的pages.php

class Pages extends CI_Controller {
    function __construct() {
        parent::__construct();

        $this->name = $this->uri->segment(2);
    }

    public function index($variable = NULL)
    {
        dd($variable);

        if(is_page($this->name))
            load_view("$this->name/home");
        else
            load_view('errors/error_404');
    }
}

1 个答案:

答案 0 :(得分:4)

我想你想要这个

$route["sisters/adab/(:num)"] = "frontend/pages/index/$1"; //correct

$route["sisters/adab/(:num)"] = "frontend/pages/$1"; // is wrong because 
//it is redirecting to your page's controller and looking for a method (:num)