Welcome Guest, Not a member yet? Register   Sign In
Exiting the application - simple issue
#1

[eluser]EEssam[/eluser]
Hello,

I need to check for something in my Controller constructor and if the condition is met, I need display a view and exit the application.

if (1 == 1)
{
$this->load->view('closed', $this->data);
exit;
}

The code above is showing a blank page.

Please help.
#2

[eluser]libnac[/eluser]
I think you should only load a view and quit the exit function because CI will never renders the final output.

Also, you can use $this->output->set_output($any_text_or_html) in order to display any message.
#3

[eluser]EEssam[/eluser]
Hi,

If I remove the exit function the rest of the code will be executed Sad

I just need to show the view called 'closed'
#4

[eluser]libnac[/eluser]
Enclosed rest of code with an else sentence can be a solution
#5

[eluser]EEssam[/eluser]
I thought about that but it's not logical at all.

What if the visitor supply a method name that do exist? It will be executed unless I put my code in every method I have!!!
#6

[eluser]ontguy[/eluser]
You could try using "return;" instead of "exit;".
#7

[eluser]arume[/eluser]
Maybe putting this in your controller:

Code:
function _remap($method)
{
  if (1 == 1)
  {
    $this->load->view(’closed’, $this->data);

    return false;
  }
  else
  {
    if (!method_exists($this, $method))
    {
      show_404();
    }

    return call_user_func_array(array(&$this, $method), array_slice($this->uri->rsegments, 2));
  }
}

Of course, you must change 1 == 1 for your logic.
#8

[eluser]Rick Jolly[/eluser]
It won't work because of CI's output buffering. Try this:
Code:
ob_start();
$this->load->view('closed', $this->data);
ob_end_flush();
exit();
#9

[eluser]EEssam[/eluser]
Thanks guys, Rick's code worked fine.
#10

[eluser]arume[/eluser]
[quote author="Rick Jolly" date="1214005320"]It won't work because of CI's output buffering.[/quote]

I am using it and, as far as I know, it works. Can you say me where is the error?
Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB