In my Application
I have 3 routing rules (defined in routes.php
file) thats directed to the one controller
$route[urlencode('news')] = "news/show-news";
$route[urlencode('letters')] = "news/show-news";
$route[urlencode('papers')] = "news/show-news";
so
if any user navigate to any of those URLs
http://example.com/news/
http://example.com/letters/
http://example.com/papers/
The target controller will be news/show-news
My need
How to identify Routing rule that used that directed to my Codeigniter controller?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {
public function show-news(){
// came from [news OR letters OR papers] ??
}
}
First thanks to @aspirinemaga
His answer is correct
But if we want to do that without using parametric controller function
We can do that
public function show-news(){
// came from [news OR letters OR papers] ??
$requested_URI_segment = $this->uri->segment(1);
$requested_URI_segment = urldecode($requested_URI_segment);
switch ( $requested_URI_segment ){
// If news requested
case 'news':
// your code here
echo 'news requested'. '</br>';
break;
// If letters requested
case 'letters':
// your code here
echo 'letters requested'. '</br>';
break;
// If papers requested
case 'papers':
// your code here
echo 'papers requested'. '</br>';
break;
// Default landing if nothing provided
default:
// your code here
echo 'select one of the show method'. '</br>';
}