Welcome Guest, Not a member yet? Register   Sign In
call function without parameters
#1

[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
#2

[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?
#3

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB