I’m using codeigniter and have a main view that calls another view based on a param I pass it, so for instance I might pass something like this from the controller:
$data['view'] = 'login';
$this->load->view('main', $data);
This all works fine and dandy, however, I’m trying to pass in my error pages the same well. In my error pages I have something similar to my controller where I set a view and then call the main view.
This works fine if I have not processed any views yet, for instance if I get a PHP error in the controller. However if I get an error in the view, it will process the main view twice (hence html/head/body tags twice)
If i just spit out the error page without the main view the content could go anywhere, say a title tag for instance, so I need to regenerate the whole page.
I know it’s in the middle of processing the current view so there it doesn’t really make sense to clear the output of something that is currently generating output, but is there anyway to do this. Meaning when the error page hits, clear anything generated and then just output whatever from the error page?
The data strings is a good idea, however I didn’t really want to rewrite anything in the app, we must have around 200 views.
I ended up playing with the object buffer in PHP and put this in the top of each error file: