I'm trying to simplify this code to a fewer lines.
// Controller function routing
$route['news/popular'] = "news/popular";
$route['news/featured'] = "news/featured";
$route['news/latest'] = "news/latest";
$route['news/index/(:any)'] = "news/index/$1"; // points to a url slug of article
$route['news/(:any)'] = "news/index/$1"; // points to article without 'index' segment
To this:
$route['news/(:any)'] = "news/$1";
$route['news/(:any)'] = "news/index/$1";
$route['news/index/(:any)'] = "news/index/$1";
Not working at all. Are there any other methods for this? or should I stick to the long code?
No you can't do that way in codeigniter routes as how can codeigniter guess which function you want to use.
What you can try to reduce your routes is categorize news in single function.Something like this :
function get_news($news_type)
{
//check here which type of news is required and process accordingly.
}
In your route it goes like this
$route['news/(:any)'] = 'news/get_news/$1';
Hope this help you