I have a function
function do_something() {
// process
$this->load->view('some_view', $data);
exec('mv /path/to/folder1/*.mp3 /path/to/folder2/');
}
My intention is to move files after outputting the view. But apparently it is done before rendering the view. My question is, does $this->load->view(); have to be the final step in a function?
I did a little research, and seems like my question is similar to this topic. Correct?
Why don’t you just use a
post_systemhook? It’s called after the final page is sent to the browser, that way you can load views normally, without echoing them out.Here’s an example controller:
And an example hook:
Check out the hooks user guide for info on setting them up. They are your friends!
EDIT: Something I just thought of…
If you’re only going to be doing this inside one controller method… it would probably be better to use Phil’s approach. This would avoid having a hook call for every request which would be unnecessary if you only need it once.
Another thing you could do, if you only need it once, is use CI’s
_output()handler for Controllers (info here). That would work like this: