passing a variable back to a function |
[eluser]Unknown[/eluser]
Hello, my question is, if I have a function called test1() and this function is called in my controller: Code: $this->test1(); but I also wish a function called test2 to pass a variable to it later in the code. Code: public function test2(){ My program throws an error because $passed is not needed the first time. Do I need to override test with another implementation. How would I do this. Sorry if this is a basic question. Any help or advice would be greatly appreciated. Thanks PTVW
[eluser]Kamarg[/eluser]
Your example code doesn't match up with my understanding of what you said you're trying to do. That aside, you can give test1 a parameter with a default value so that it works regardless of if you pass a value to it or not. Code: function test1($param = null) {
[eluser]Unknown[/eluser]
Thanks for replying, but wouldn't that always set the value to null when its passed too? Those weren't actual extracts from the application but I didn't illustrate very well. I thought I would need to override.
[eluser]Kamarg[/eluser]
It will only be null if you don't pass a value for the variable. Check the php manual at http://www.php.net/manual/en/functions.a...ts.default for more information.
[eluser]Twisted1919[/eluser]
Code: class Blah extends CI_Controller(){ |
Welcome Guest, Not a member yet? Register Sign In |