I am using codeigniter as a module in my project to display information as categories and its items.
I want the url's like the following
- sitename.com/module/ will display all items in random order.
- sitename.com/moduel/categoryname/ will display all items in that specific category
- sitename.com/module/categoryname/title-of-the-item/ this will display the details of that specific item
here sitename.com/module/ is the root of the codeigniter and the default controller is home.
my question is how to set routes for one segment or uri and two segments of uri like
- sitename.com/module/ should load default controller(home in my case)
- sitename.com/module/categoryname/ should load home/category/categoryname
- sitename.com/module/categoryname/title-of-the-item should load index/title/title-of-the-item
i will have defined my functions as follows
- funciton index() ...
- function category($categoryname) ....
- function title($title)....
so, either i want to create a route according to the num of segments or if there is any other alternate to accomplish this with routing then that is fine.
I want to do it using the routing and not by passing the 2 segments as arguments to Index function.
so, ?
Set the base url of the site to sitename.com/module.
You could try database driven routing.
This works by using a database table to write your routes for you.
Example database table;
Example routes;
This link will give you full details (it is not my work - Google is just my friend).
the last two lines (7 and 8) is what i needed... and that served my purpose
the lines before the last two(1,2,3,4,5) is how i use pagination for the last two lines(7 and 8)
only home/category and home/ has pagination and not home/title which is the end page.
meanwhile, if anybody found the code could be buggy or need perfection then please add an answer so that i can update.