Why don't you just use the post_system hook? It is called after the last page has been sent to the browser, so you can load views normally without repeating them.
Here's an example of a controller:
class Home extends Controller { function index() { $this->move_audio = TRUE; $this->old_folder = "/path/to/folder/"; $this->new_folder = "/path/to/folder2/"; $this->load->view("some_view"); } }
And an example hook:
function post_system() { $CI =& get_instance(); if( isset($CI->move_audio) && $CI->move_audio === TRUE) { // Trim, then add trailing slash for consitency $old_folder = rtrim($CI->old_folder, "/")."/*.mp3"; $new_folder = rtrim($CI->new_folder, "/")."/"; exec("mv {$old_folder} {$new_folder}"); } }
Pay attention to the drag and drop user manual for information on setting them up. They are your friends!
EDIT: something I was just thinking about ...
If you intend to do this in only one controller method, it is probably best to use the Phil approach. This would avoid calling the hook for each request, which would be superfluous if you need it only once.
Another thing you could do if you only need to be done once is to use the CI _output() handler for the controllers ( information here ). This will work as follows:
class Home extends Controller { // Initalize the var to avoid having to // check if it set or not var $move_audio = FALSE; // CONTROLLER METHOD function index() { $this->move_audio = TRUE; $this->old_folder = "/path/to/folder/"; $this->new_folder = "/path/to/folder2/"; $this->load->view("some_view"); } // OUTPUT HANDLER function _output($output = "") { echo $output; if($this->move_audio === TRUE) { // Trim, then add trailing slash for consitency $old_folder = rtrim($this->old_folder, "/")."/*.mp3"; $new_folder = rtrim($this->new_folder, "/")."/"; exec("mv {$old_folder} {$new_folder}"); } } }
bschaeffer
source share