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"

  1. if url www.example.com/uk-en/category want "category"
  2. 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -