Welcome Guest, Not a member yet? Register   Sign In
Sending output to browser
#1

[eluser]steelaz[/eluser]
Based on certain conditions, I want to break in the middle of controller and send custom output to the browser. I found a way to do this using private function _display() in output class, but perhaps there is proper way of doing it?

This is what I use right now:
Code:
$this->output->set_header($json_header);
$this->output->set_output(json_encode($result));
$this->output->_display();
exit(0);
#2

[eluser]Jondolar[/eluser]
I don't think you need to call the _display() function. Just don't display anything else after you set the output.
#3

[eluser]steelaz[/eluser]
You're right, I don't have to, but I would prefer it to keep my coding style. This is what I like to do:

Code:
if ($step1 == FALSE)
{
    // Log error, etc,
    redirect('controller');
}
if ($step2 == FALSE)
{
    // Log error, etc,
    redirect('controller');
}

// No errors, do something

Instead of coding like this:

Code:
if ($step1 == TRUE)
{
    if ($step2 == TRUE)
    {
        // No errors, do something
    }
    else
    {
        // Log error, etc,
    }
}
else
{
    // Log error, etc,
}

But in this case, instead of redirecting on error I'd like to send custom output.
#4

[eluser]Colin Williams[/eluser]
How about loading a view? I think I'm missing the problem.




Theme © iAndrew 2016 - Forum software by © MyBB