I am using codeigniter to create different components. Each component belongs to a city. e.g london will have 3 component/functions I want to create url like below
mydomain.com/london/component1
mydomain.com/london/component2
mydomain.com/london/component3
Similarly for any generic city
mydomain.com/city/component1
mydomain.com/city/component2
mydomain.com/city/component3
I want to use one controller and its function for this purpose. how can i create routes for this.
Hope this will help you :
in config.php
/*here mydomain.com*/
$config['base_url'] = 'http://example.com';
Your route.php
should be like this:
$route['(:any)'] = 'city/$1';
$route['(:any)/(:any)'] = 'city/$1/$2';
$route['default_controller'] = 'city';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Your City Controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class City extends CI_Controller {
public function __construtct()
{
parent::__construtct();
$this->load->helper('url');
}
public function london($component=NULL)
{
echo $component;die;
}
}
Your links :
/* index */
mydomain.com/
/* for london output : component */
mydomain.com/london/component