0

I've altered routes.php

$route['category']='Home/category';

for making url look like www.website.com/category insteead of www.website.com/Home/category. Since Home is my default controller. but if i am using $this->uri->segment(); inside category function, its not working. this is my controller

class Home extends CI_Controller {

  public function category()
  {
     $value=$this->uri->segmet(3);
  }
}

And my url is www.website.com/category/books I am getting result if I dont alter routes. But by altering routes, I need this to work. Please help me. Thanks

Ramkisan
  • 11
  • 6

4 Answers4

1

You can debug what you have there by:

var_dump($this->uri->segment_array());

this will give you array of all segments in URI.

Also you can try to debug with this method:

var_dump($this->uri->rsegment_array());

this will give you array of all routed segments in URI

Respectivelly, you can use $this->uri->segment() or $this->uri->rsegment() what ever you find more appropriate for your application.

Tpojka
  • 6,996
  • 2
  • 29
  • 39
1

hello please check segment spelling in your code

class Home extends CI_Controller {

  public function category()
  {
     $value=$this->uri->segmet(3); //wrong 
     $value=$this->uri->segment(3); 
  }
}
Divyesh
  • 389
  • 2
  • 12
0

First of all you need to load URL library and than if your URL is:

www.website.com/category/books

And you want to get books from URL than segment should be:

$value=$this->uri->segment(2); //books
devpro
  • 16,184
  • 3
  • 27
  • 38
0

My URL libraries are in autoload. Anyway I solved it. I just configured my routes like this $route['category/(:any)']='Home/category/$1'

Ramkisan
  • 11
  • 6