编程语言
首页 > 编程语言> > PHP-Codeigniter路由任何或num不起作用

PHP-Codeigniter路由任何或num不起作用

作者:互联网

我有类似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';

控制器:前端文件夹内的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');
    }
}

解决方法:

我想你要这个

$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)

标签:codeigniter,codeigniter-2,codeigniter-routing,codeigniter-url,php
来源: https://codeday.me/bug/20191028/1955961.html