Jump to content

Pedro Bernal

Member Since 22 Jan 2014
Offline Last Active Feb 20 2015 12:35 AM

Topics I've Started

How to add some custom anotations in a Form

10 February 2015 - 06:29 AM

Hi, I want to know if is there a way to add some aclarations or anotations for fields into a groceryCrud form, in order to clarify what information should the user enter in some tricky fields.



Problem auditing queries in Codeigniter with Grocerycrud

24 September 2014 - 03:45 PM

I need to audit the insert, edit and delete queries from my application, I tried using a hook that calls a model that save the query into a table in my database, however it is just saving the SHOW, DESCRIBE and SELECT statements, but the update, adding and deleting actions that I perform on the GroceryCrud views are not being saved.

Can someone help me to figure it out why, Thanks!

Hook code:

class Db_log {

    function __construct() 

    function logQueries() 
        $CI = & get_instance();
        $filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.php'; // Creating Query Log file with today's date in application/logs folder
        $handle = fopen($filepath, "a+");                 // Opening file with pointer at the end of the file
        $times = $CI->db->query_times;                   // Get execution time of all the queries executed by controller
        foreach ($CI->db->queries as $key => $query) 
            $sql = $query . " \n Execution Time:" . $times[$key]; // Generating SQL file alongwith execution time
            fwrite($handle, $sql . "\n\n");              // Writing it in the log file
            $CI->model_log->log($sql);                     // Calling the model
        fclose($handle);      // Close the file




Model code:

Class Model_log extends CI_Model
 public function log($sql)
      $this-> db ->select('*');
      $this-> db ->from('usuarios');
      $this -> db -> where('nombre', $_SESSION["usuario"]);
      $query = $this->db->get();
      $user_data= get_object_vars($query->row());
      $sql = str_replace("'", "", $sql);
      $date = date('Y-m-d H:i:s', time());
          INSERT INTO `log`(`query`, `usuario`, `fecha`)



Error with query using mayor or equal in Grocery Crud and Code Igniter

26 May 2014 - 05:34 PM

I am having an issue with grocerycrud, I am collecting decimal values every 5 minutes and storing them into a table named medidas_ludlum_5min, I have a view that allows to the user select a date range, a value and ">", "=" or ">=" options.

After that I process the selection with a switch in my controller and with GroceryCrud I am showing the results of the query.

When I select values higher than 0, it works good and I have two results:


and measurement > "'.$medida.'"
and fecha between "'.$fechainicio.'" and "'.$fechafin.'")',null,FALSE);



10_____________________________22/04/2014 - 17:18

11.5___________________________22/04/2014 - 17:23

However using the same date range with >= than 0 I just got the cero values.


and measurement >= "'.$medida.'"
and fecha between "'.$fechainicio.'" and "'.$fechafin.'")',null,FALSE);



0______________________________22/04/2014 - 17:13

0______________________________22/04/2014 - 17:28

0______________________________22/04/2014 - 17:33

0______________________________22/04/2014 - 17:38

0______________________________22/04/2014 - 17:43

As you can see the two values higher than cero are not presented in the groceryCrud table.


As an additional note I am using the same query to feed a google chart and it works perfect:

$sql = $this->db->query('SELECT * FROM medidas_ludlum_5min where FK_ludlum="'.$id.'"
and measurement >= "'.$medida.'"
and fecha between "'.$fechainicio.'" and "'.$fechafin.'"');

I dont know why is this happening any help will be apreciated, If someone needs more code just tell me and I can post it or message it.


Issue whith export and print buttons

13 March 2014 - 04:13 PM

Hi there I am having an issue: The export and print buttons doesnt work when I include a where method into my controller function, is there a way to fix it?.





Here is the code of my controller.

 $fechainicio = $this->input->post('fechainicio');
      $fechafin = $this->input->post('fechafin');
      $crud = new grocery_CRUD();
      $crud->where('fecha >=',$fechainicio);
      $crud->where('fecha <=',$fechafin);
      $crud->columns('fksitio', 'fecha', 'resultado','comentarios','adjunto');
      $crud->edit_fields('fksitio', 'fecha', 'resultado','comentarios','adjunto');
      $output = $crud->render();
      $data['username'] = $session_data['username'];
      $data['level'] = $session_data['level'];
      $this->load->view('CRUD_Formatos.php', $output);

disable buttons in add/edit forms

11 March 2014 - 09:46 PM

Hi, I want to know if there is a way to disable the button "Save and go back to list" in the add form, or where is it in the code?, so I can edit it.