Exit early and still output benchmark info |
[eluser]The Fox[/eluser]
Hi all, I sometimes want to end script execution early if there's an error so I don't have too many levels of if statements. The example I've been working on is a page that displays the details of one record from the database. The query must return exactly one result, otherwise I want to give an error message and end the script right there. The most obvious code to do this is: Code: echo $this->load->view('outer', $data); This code seems to fix that: Code: $this->load->view('outer', $data); Thanks, Matt PS I've a few months in to coding with CI, and enjoying PHP again. Thanks Derek and everyone!
[eluser]eggshape[/eluser]
Hi Fox - If you want to exit from a function but not exit the script, use 'return' (you don't need to return a specific value); If you want to exit out of a loop, use 'continue' http://us2.php.net/manual/en/control-str...ntinue.php
[eluser]BoltClock[/eluser]
Correction to eggshape's reply: to bail out of a loop, use break, not continue.
[eluser]The Fox[/eluser]
Thanks egg- I'm so used to procedural PHP I forgot the controller is a function and I can use Code: return; |
Welcome Guest, Not a member yet? Register Sign In |