I’m really stuck in doing routes for my app and I find rooting in CI very confusing
so what I have is some pages of people in each country, and you get to that page by selecting a country in a drop list in the home page
I manage to pass data using POST method, but the problem is I can’t access these pages directly by a url, because their main controller do access to db and generate them
so for now all my pages have this url
www.site.com/country
country is a controler
but i want is to look like this:
www.site.com/name-of-country/name-of-person
any idea how to do that?
These answers don’t give enough info, and the accepted answer is just terrible…
The best way to handle this would be to set up your routing to do the following (if you want to control the countries that the users are able to use:
put this in your routes file:
what this does is takes your array of allowed countries and then creates a routing rule for each country, so if a user goes to
http://example.com/japan/naruto, it routes to the urlhttp://example.com/country/view/japan/naruto. This is assuming that ‘japan’ is in your ‘allowed countries’ array.The second one simply routes the url
http://example.com/japantohttp://example.com/country/view/japaninto your controller
country.php:what I have done here is enabled you to create a page just for the country that is displayed which loads the
countries_view.phpout of your views folder, or you can view the page for the user, which loads theusers_view.phppage.