Welcome Guest, Not a member yet? Register   Sign In
Default parameters for controller functions
#1

[eluser]chaotiq[/eluser]
Can I give a default parameter for controller functions and then override with a uri?

Consider the following code.
Code:
Class My_controller extends Controller{

    function my_function($var = 0)
    {
        if ($var == 0)
        {
            //do stuff
        }
        else
        {
            //do other stuff
        }
    }
}

If I call the function without giving it a parameter the first part of the if statement works as intended. However, if I try to go to:

http://mysite.com/index.php/my_controlle...nction/213

I would expect the 213 to override the default of 0 and the else should run. When I try this the first part of the if statement still runs.

Am I thinking about this wrong?

[Edit: formatting]
#2

[eluser]danmontgomery[/eluser]
Works for me:

Code:
class test extends Controller {
    
    public function my_function($var = 0)
    {
        echo "\$var is " . $var;
    }

}

/test/my_function

Quote:$var is 0

/test/my_function/213

Quote:$var is 213
#3

[eluser]chaotiq[/eluser]
It does work. Thank you for testing it and your time. I misspelled one letter and one of my functions was not returning the right data. I feel ashamed. :roll:

Thanks again for testing it out.
#4

[eluser]danmontgomery[/eluser]
Wink




Theme © iAndrew 2016 - Forum software by © MyBB