![]() |
Variable in all functions in Controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Variable in all functions in Controller (/showthread.php?tid=36209) |
Variable in all functions in Controller - El Forum - 11-25-2010 [eluser]Jareish[/eluser] Hi, I have a page in my CMS which consists of different parts. For instance you can add a category in 1 sidebar, and edit settings in another. Adding a category goes through a different function then saving settings. And thus generates other error feedback. My controller looks something like this Code: <?php when you click on a project on the members page, it loads the editProject function, loading lots of stuff from the database, everything stored in $data. What I want to do is, when I add a category, to send the $data['message'] to the editProject function because I don't want to load all the same stuff in the addCategory fucntion. I don't want to do this with a function parameter, because the editProject function has to work without it. So the best way would be (I think) is to set a variable in the controller, then use a redirect in the addCategory function. the editProject() would read that variable from the controller (or leave it empty if nothing is in it). and send it to the corresponding view. I've seen alot of tutorials, but from what I've seen, they all do a redirect to a different view on success/fail. But I want it to be the same view, with a reserverd Div for errors. I've read stuff on the forum about adding a global $message in the constructor, and then again in every function you use Code: global $message; I then got something like this: Code: <?php But I still get and error (not defined). Any ideas what Im doing wrong? Variable in all functions in Controller - El Forum - 11-25-2010 [eluser]Deveron[/eluser] Hi Jareish, here is a solution but it doesn't work with redirect. Controller: Code: <?php In this case the URL will not change. It will still show addCategory. Cheers Variable in all functions in Controller - El Forum - 11-25-2010 [eluser]Jareish[/eluser] Hi, thanks mate, this seems solid ![]() ![]() ![]() php scoping is one of the biggest issues I had to deal with (I find it alot easier in AS3 for some reason). Cheers |