-1
I’m using hook to log queries. However when I use redirect instead of load->view
, the array db->queries
is empty. I need to continue using the redirect statement. Can anyone help me?
I’m using this model:
$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 a $this->view("unimed")
I’m using redirect(base_url().'unimed');
What I realized is that when using Redirect, it loses (or restarts) the entire controller.. and hence the array values $this->db->queries
empty
I need to continue using redirect for the following reason:
when using a load->view()
the url remains the last one passed. And with redirect the url comes clean
ex: with
load->view("unimed")
after saving a record
url comes: localhost/profit/manager/Unimed/write/? id=&par=
ex: with
redirect(base_url().'unimed')
after saving a record the url comes localhost/profit/manager/Unimed
You need to give more details. When this hook is excommunicated? could you put his code? and the function where is the
redirect()
?– rray
I’m using this model.
– Jairo Gratão