• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to exit() ?

#1
[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?

#2
[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.

#3
[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) {
  
  $this->load->view('under_maintenance');

  exit;
  
}

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)

#4
[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) {
  
  $this->load->view('under_maintenance');

  exit;
  
}

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(){
if(UNDER_MAINTENANCE) {
  _maintenance();
else
  _normal();
}
}

function _maintenance(){
  $this->load->view('under_maintenance');
}

function _normal(){
  $this->load->view('index');  
}

what do you think?
Or else directly in the function you want to call
But so maybe the code is cleaner for maintenance

#5
[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) {
  
  $this->load->view('under_maintenance');

  exit;
  
}

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(){
if(UNDER_MAINTENANCE) {
  _maintenance();
else
  _normal();
}
}

function _maintenance(){
  $this->load->view('under_maintenance');
}

function _normal(){
  $this->load->view('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! Smile

#6
[eluser]danmontgomery[/eluser]
*cough*

Code:
function index(){
  if(UNDER_MAINTENANCE) {
    $this->_maintenance();
  else
    $this->_normal();
  }
}

function _maintenance(){
  $this->load->view('under_maintenance');
}

function _normal(){
  $this->load->view('index');  
}

#7
[eluser]Buso[/eluser]
[quote author="noctrum" date="1271973152"]*cough*

Code:
function index(){
  if(UNDER_MAINTENANCE) {
    $this->_maintenance();
  else
    $this->_normal();
  }
}

function _maintenance(){
  $this->load->view('under_maintenance');
}

function _normal(){
  $this->load->view('index');  
}
[/quote]
haha we get lazy when mr. interpreter isn't there to yell at us Tongue

#8
[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.

#9
[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) {
  $route['(:any)'] = "maintenance";
}

and a controller and view maintenance


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.