skip to Main Content

My current URL is like:

(this url is already shorten by using routes)
Here get_city is my method name and now what i exactly want is

1)remove controller name from url

2)pass selected city value from dropdown and set in URL as a parameter

So,Required url is: OR

NOTE:I know how to use routes but in such case how to make dynamic URL?!
AND please don’t give me direct reference of ellislab docs because i have already tried those things



  1. For dynamic route in codeigniter:

    try like this:

    in your routes.php file copy and paste these codes:

    require_once (BASEPATH . 'database/DB' . EXT);
    require_once (BASEPATH . 'helpers/url_helper' . EXT);
    require_once (BASEPATH . 'helpers/text_helper' . EXT);
    $db = &DB();
    $query = $db -> get('news');
    $result = $query -> result(); //result return all records
    foreach ($result as $row) {
        $string = rawurlencode(str_replace(' ', '-', strtolower($row -> subject)));
        $route[$string] = "controller/news_details/$row->id";

    so you can , change $string with any string that you want.

    then try type new url and see Routes will work fine.

    NOTE:.htaccess file must be removing index.php in url

    hope this help.

    Login or Signup to reply.
  2. You can try with the method “_remap”.

    Check the official documentation for more info about the behavior of the function:


    Login or Signup to reply.
  3. You need to config routes in application/config/routes.php

    After existing routes add

    $route['([a-z]+)'] = 'controller_name/method_name/$1';

    But this overwrite all routes and before this route you need to declare all routes for you controllers

    $route['product/:any'] = 'product/$1';
    $route['catalog/:any'] = 'catalog/$1';

    and after

    // this route be used when previous routes is not suitables
    $route['([a-z]+)'] = 'controller_name/method_name/$1'; 


    CI2: URI Routing

    CI3: URI Routing

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top