CodeIgniter Forums

Full Version: call function without parameters
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]martin79[/eluser]
Hi Forum,

I am a bit confused setting up the structure of my app to be logical and
work fine with breadcrumps.

I have a controller, lets say
Code:
Country extends Controller{}
A country can have city tours, therefore I created a function
Code:
city_tours($tour){
if($tour=='some-tour'){...}
}

That will now create URLs like /country/city_tours/some-tour
If someone now just calls
Code:
/country/city_tours
I want to return a general view
about city tours or something like that.

But this now throws an "Missing argument" error, since the function
Code:
city_tours($tours){}
is expecting a parameter.

As far as I know PHP cannot overload functions and that wont let me create a function
Code:
city_tours()
.

Any ideas how to acomplish this? URL Rewrite?

Martin

El Forum

[eluser]martin79[/eluser]
oh.. I think thats what routing is for...

This would help me:
$route["country/city_tours"] = "country/city_tours/all";

Where "all" is a function that will return all city tours.

Right?

El Forum

[eluser]xwero[/eluser]
just set a default to you parameter to make it optional.

El Forum

[eluser]martin79[/eluser]
Mhh..that also works. Didnt know that...
Thanks!

El Forum

[eluser]Colin Williams[/eluser]
http://us3.php.net/functions