I'm using hook for queries log. However when I use redirect instead of load->view
, the db->queries
array is empty. I need to continue using the redirect statement. Can someone help me?
I'm using this template :
$hook['post_controller'] = array( // 'post_controller' indicated execution of hooks after controller is finished
'class' => 'Db_log', // Name of Class
'function' => 'logQueries', // Name of function to be executed in from Class
'filename' => 'db_log.php', // Name of the Hook file
'filepath' => 'hooks' // Name of folder where Hook file is stored
);
class Db_log {
var $CI;
function __construct() {
$this->CI = & get_instance(); // Create instance of CI
}
function logQueries() {
$filepath = APPPATH . 'logs/QueryLog-' . date('Y-m-d') . '.php'; // Filepath. File is created in logs folder with name QueryLog
$handle = fopen($filepath, "a+"); // Open the file
$times = $this->CI->db->query_times; // We get the array of execution time of each query that got executed by our application(controller)
foreach ($this->CI->db->queries as $key => $query) { // Loop over all the queries that are stored in db->queries array
$sql = $query . " \n Tempo de execução:" . $times[$key]; // Write it along with the execution time
fwrite($handle, $sql . "\n\n");
}
fclose($handle); // Close the file
}
The controller, instead of using $this->view("unimed")
I'm using redirect(base_url().'unimed');
What I realized is that when using Redirect, it loses (or restarts) the whole controller .. and hence the values of the array $this->db->queries
is empty
I need to continue using redirect for the following reason:
when using a load->view()
the url continues being the last one that was passed. And with the redirect the url comes clean
eg with
load->view("unimed")
after saving a record
the url comes from: localhost / profit / manager / unimed / save /? id = & par =
Eg:
redirect(base_url().'unimed')
After saving a record to url comes localhost / profit / manager / unimed