php - unlimited parameters get last one -
i'm using codeigniter. how can last part of url like:
www.example.com/uk-en/category/subcategory
parameters may unlimited or there may one. inside of controller home , method index, want last part of url e.g "subcategory"
- if url www.example.com/uk-en/category want "category"
- if url www.example.com/uk-en want "uk-en"
edit
if url www.example.com/home/index/uk-en/category it's working
want without class name "home" , method "index"
like 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]
use in routs
$route['(.*)'] = "home/index";
this print routs in controller in index function
print_r($this->uri->segment_array());
Comments
Post a Comment