rookie question - Sharing variable between functions |
[eluser]zoonix[/eluser]
I'm playing around trying to learn CI and so far it's great. I just have a question that is probably really basic. So I hope someone can point me in the right direction. What is the best way to pass some data from one function to another in a controller? If I have several functions and each one generates a status message when called. So how would I pass that message along to the index function. Or am I just completely daft and going about it all wrong? Here's my test simple test code... Code: <?php Thanks!
[eluser]nelson.wells[/eluser]
Message could be a member of the controller class (in this case, Test). Instead of saying $message = "blah blah"; you would do $this->message = "blah blah blah". Since it is a member of the class, it doesn't go out of scope.
[eluser]n0xie[/eluser]
You should make a class variable of it if you want to share it between functions: Code: // instead of You also might want to take a look at my message library for passing messages around ;-)
[eluser]zoonix[/eluser]
Thanks Nelson, that looks like the simple answer I knew I was missing! I will give a go tonight. n0xie's, your message library looks quite useful as well. Thanks man! |
Welcome Guest, Not a member yet? Register Sign In |