Reputation: 8705
I am a bit new to the routing with CI, and I don't understand it quite well (to be honest not at all). I have following url which need to be changed:
domain.com/mali_oglasi/index/1(some number)
It is used for pagination, and I need it to be shorten to:
domain.com/mali_oglasi
I tried:
$route['mali_oglasi/index/(:num)'] = 'mali_oglasi';
but it doesn't seems to work(nothing is changed). What am I doing wrong, what needs to be changed?
Index function from the controller mali_oglasi:
function index() {
$config['base_url'] = base_url().'mali_oglasi/index';
$config['total_rows'] = $this->db->count_all('ad');
$config['per_page'] = 10;
$this->pagination->initialize($config);
$data['pagination_links'] = $this->pagination->create_links();
$data['title'] = "Mali Oglasi | 010";
$data['oglasi'] = $this->mgl->mgl_get_all_home($config['per_page']);
$data['loc'] = $this->gi_loc;
$data['cat'] = $this->gi_cat;
$data['stylesheet'] = $this->css;
$data['main_content'] = 'mali_oglasi';
$this->load->view('template',$data);
}
Upvotes: 1
Views: 277
Reputation: 4456
try this
$route['mali_oglasi/(:num)'] = 'mali_oglasi/index/$1';
it will help you http://codeigniter.com/user_guide/general/routing.html
and for pagination you can add this
$config['uri_segment'] = 3;
its optional but better to add
Upvotes: 0
Reputation: 4830
Try:
$route['mali_oglasi/(:num)'] = 'mali_oglasi/index/$1';
Your domain.com/mali_oglasi/index/1 can then be accessed at domain.com/mali_oglasi/1
Edit: To loose the /1 just do:
$route['mali_oglasi'] = 'mali_oglasi/index/1';
Upvotes: 0
Reputation: 2065
You need to use .htaccess for what you are trying to achieve, more importantly, the "mod_rewrite" part:
https://www.google.co.uk/search?q=htaccess+rewrite
CodeIgniter routing doesn't change the look of the URL, it simply changes it's destination.
Upvotes: 1
Reputation: 704
Codeignitor routing is simple as
serverpath(base_url)/controller/method(function)/para1/valu1/para2/valu2...
you hide index file from defining .htaccess rule(creating file).
more info please visit : user_guide in Easily you are understand.
Upvotes: 0