I'm using codeigniter. How can I get last part of my URL like:
www.example.com/uk-en/category/subcategory
Parameters may be unlimited or there may be only one. Inside of my Controller Home and method Index, I just want last part of url e.g "subcategory"
- if url is www.example.com/uk-en/category I want "category"
- if url is www.example.com/uk-en I want "uk-en"
Edit
if url is www.example.com/Home/index/uk-en/category then it's working
but What i want without class name "Home" and method "index"
Like this www.example.com/uk-en/category
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller{
public function index($params=[]){
$params=func_get_args();
$last=end($params);
echo $last;
}
}
?>
routes.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['(:any)'] = 'Home/index';
$route['default_controller'] = 'Home';
$route['404_override'] = 'error_404/index';
$route['translate_uri_dashes'] = FALSE;
?>
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]