In the PHP MVC framework, how can I cleanly and elegantly exit the current controller / action, but continue to execute the script
For example, suppose my framework usually follows this outline:
- Map URL for controller / action
- Instant controller control, action call (capture output)
- Make stuff
- Render view
- At the end of the method of continuing normal operation
- Process exit if necessary
- Send output to browser
Now let's say that I want to stop the “normal” execution somewhere in the “Do” step in order to, say, display a different view or redirect the title, and I want to stop processing the rest of the body Action, but continue on the “Exit the process” step
How can I achieve this in the best way? My only ideas:
protected function redirect($url) {
header("Location: $url");
exit();
}
but this completely skips the rest of the wireframe execution and flushes everything that was in the output buffer directly to the user. Alternative:
call_user_func_array(array($controller,$action),$params);
afterwards:
...
protected function redirect($url) {
header("Location: $url");
goto afterwards;
}
However, this makes me twitch and runs counter to everything that I have learned, especially because the label to which it refers is in another file completely.
So, is there any other way to achieve this?
. , , exit(), . .