I'm just learning about codeigniter and am stumped by the following:
I have these routes in my routes file:
$route['(:any)'] = 'pages/view';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['default_controller'] = 'pages/view';
Yet when i load http://mysite/index.php/news," it loads the news page rather than 'pages/view,'. I thought that because I have the catchall route at the top, this page would also just load pages/views.
Where am i going wrong?
The reason is :any doesn't match slash, at least since CI 3.0+ . So your first route rule is not a "catch all" any longer. http://www.codeigniter.com/user_guide/installation/upgrade_300.html?highlight=any#routes-containing-any
any and num is important for routing in codeigniter.
we will use any for the string value such as order001.
we will use num for the integer value such as 001.
$route['(:any)'] = 'pages/view/$1';
$1 is define for the first parameter.
$route['(:any)/(:any)'] = 'pages/view/$1/$2';
for 2 parameter pass in url.