CodeIgniter Forums
Exiting 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: Exiting Controller (/showthread.php?tid=11264)



Exiting Controller - El Forum - 09-02-2008

[eluser]spider pig[/eluser]
I have created a form and my controller script validates it and builds an error message in the variable $errorMessage. I then test if $errorMessage is not NULL, I display the form again with an error box. I then want to exit the script:
Code:
// header displayed earlier in code
if ($errorMessage != NULL) {
    $row->al_error_message = $this->error->error_box($errorMessage);
    $this->load->view('newsletter_form', $row);
    $this->load->view('footer', $settings);
    exit;
}

However, nothing displays. Is there a way to output what is already passed to output before I exit?

Thanks


Exiting Controller - El Forum - 09-02-2008

[eluser]Jilani Jidni[/eluser]
[quote author="Dale Rodgie" date="1220356597"]I have created a form and my controller script validates it and builds an error message in the variable $errorMessage. I then test if $errorMessage is not NULL, I display the form again with an error box. I then want to exit the script:
Code:
// header displayed earlier in code
if ($errorMessage != NULL) {
    $row->al_error_message = $this->error->error_box($errorMessage);
    $this->load->view('newsletter_form', $row);
    $this->load->view('footer', $settings);
    exit;
}

However, nothing displays. Is there a way to output what is already passed to output before I exit?

Thanks[/quote]

Your code does not seems any problem. are you sure your program enter into the if condition. if yes then check this function
Code:
$this->error->error_box($errorMessage);
. and also debug your code......


Exiting Controller - El Forum - 09-02-2008

[eluser]Mark van der Walle[/eluser]
Since a while exiting in controllers might not show any output (due to partial view support). The best (and also cleanest way) is:
Code:
// header displayed earlier in code
if ($errorMessage != NULL) {
    $row->al_error_message = $this->error->error_box($errorMessage);
    $this->load->view('newsletter_form', $row);
    $this->load->view('footer', $settings);
    return;
}



Exiting Controller - El Forum - 09-02-2008

[eluser]spider pig[/eluser]
Thanks Mark. It works a treat.