I'm kind o开发者_开发问答f new to CodeIgniter.
I need to design a simple website where I pull out information from a Database. The information from the database is about Ads. I have information about the Country, Country Zone, Zone Location and the kind of the Ad.
My goal is to have an URI like:
http://www.someurl.com/index.php/country/country_zone/zone_location/ad_type/title_of_ad
There are some information out there on how to do this with CodeIgniter?
Best Regards,
I think the easiest way is with a custom route in your application/config/routes.php
. Something like this:
$route['^(:any)/(:any)/(:any)/(:any)/(:any)'] = "your_controller/get_ads/$1/$2/$3/$4/$5";
then your controller function would look something like:
function get_ads($country, $country_code, $zone_location, $ad_type, $title_of_ad) {
// your code
}
.. you can replace (:any)
with a more specific regular expression if there is some pattern to the arguments.
the first 2 arguments in your link are your controller name and the method of that controller you want to call.
so
http://www.someurl.com/index.php/country/country_zone/zone_location/ad_type/title_of_ad
would mean that you call the country_zone
method of your country
controller and pass zone_location, add_type and title_of_ad to that method.
what you want ist
http://www.someurl.com/index.php/TheControler/themethod/country/country_zone/zone_location/ad_type/title_of_ad
implemented like that:
class TheControler extends Controler{
function themethod($country,$country_zone,$zone_location,$ad_type,$title_of_ad){
//your code
}
}
精彩评论