How to exit() ? - 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: How to exit() ? (/showthread.php?tid=29819) |
How to exit() ? - El Forum - 04-22-2010 [eluser]Buso[/eluser] My problem is I would like to do something like loading a view and then exit, but without losing things like the profiler, the hooks, the error logging, and so on. If the load->view is called from the usual place (the 'outer' method in my controller. I mean, no other method is calling it), and I want to end the applicationt there, I just use 'return;'. Then the method returns to wherever codeigniter is calling it from, and continues doing its own stuff. But what happens if I wanna exit from other place? A constructor, for instance. If I use 'return;', my application won't stop there. And if I use exit, the above mentioned problems will occur (no profiler, etc). Any suggestions? How to exit() ? - El Forum - 04-22-2010 [eluser]WanWizard[/eluser] You should leave control decisions to your controller. A view is to display output, not to make logic decisions. Then, in your controller method you can use return to exit the method. How to exit() ? - El Forum - 04-22-2010 [eluser]Buso[/eluser] I didn't say I was taking decisions from within my views. :gulp: I'll give you an example, this goes inside Frontend_controller's constructor Code: if(UNDER_MAINTENANCE) { If I use return; instead of exit;, the under_maintenance view will be loaded, but - as expected - the normal page will be appended at the end (the page that would be loaded if the site wasn't under maintenance) How to exit() ? - El Forum - 04-22-2010 [eluser]Uno*[/eluser] [quote author="Buso" date="1271970679"]I didn't say I was taking decisions from within my views. :gulp: I'll give you an example, this goes inside Frontend_controller's constructor Code: if(UNDER_MAINTENANCE) { If I use return; instead of exit;, the under_maintenance view will be loaded, but - as expected - the normal page will be appended at the end (the page that would be loaded if the site wasn't under maintenance)[/quote] Code: function index(){ what do you think? Or else directly in the function you want to call But so maybe the code is cleaner for maintenance How to exit() ? - El Forum - 04-22-2010 [eluser]Buso[/eluser] [quote author="Uno*" date="1271971667"][quote author="Buso" date="1271970679"]I didn't say I was taking decisions from within my views. :gulp: I'll give you an example, this goes inside Frontend_controller's constructor Code: if(UNDER_MAINTENANCE) { If I use return; instead of exit;, the under_maintenance view will be loaded, but - as expected - the normal page will be appended at the end (the page that would be loaded if the site wasn't under maintenance)[/quote] Code: function index(){ what do you think? Or else directly in the function you want to call But so maybe the code is cleaner for maintenance[/quote] Oh ok that may work if I put it inside __construct Thanks! How to exit() ? - El Forum - 04-22-2010 [eluser]danmontgomery[/eluser] *cough* Code: function index(){ How to exit() ? - El Forum - 04-22-2010 [eluser]Buso[/eluser] [quote author="noctrum" date="1271973152"]*cough* Code: function index(){ haha we get lazy when mr. interpreter isn't there to yell at us How to exit() ? - El Forum - 04-22-2010 [eluser]Buso[/eluser] actually it won't work.. dunno why I got confused I need something to EXIT from within a constructor. If I just call $this->_maintenance, _maintenance will execute, but then the rest of the constructor will execute too, and the function requested by URI will execute too. How to exit() ? - El Forum - 04-22-2010 [eluser]Uno*[/eluser] Uhum... But if UNDER_MAINTENANCE is true do you want which all page are on maintenance? If yes you could put a "if" on route example Code: if(UNDER_MAINTENANCE) { and a controller and view maintenance |