codeigniter routes any or num not working

3.8k views Asked by At

I have url like that http://lp.dev/sisters/adab/1 but the route is not working when i use (:num) or (:any) to get the value 1 because the route give me 404 page

routes as follows

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

controller : pages.php inside frontend folder

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

There are 1 answers

1
Shaiful Islam On BEST ANSWER

I guess you want this

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