1

How do i debug my callback scripts?

I have a deal_management function which does grocery CRUD

and i have a

callback_after_insert( array( $this, ‘insert_coupon_codes’ ) );

since the insertion in the database is not working in my function insert_coupon_codes I have no way to know or view my SQL.

Is there any function by which i can debug my php scripts inside the callback function without any hacks?

I did print_r() and var_dump() but these do not seem to work inside the callback function.

sodhancha
  • 435
  • 15
  • 31

1 Answers1

6

First of all ensure that call_user_func works properly with your function. So for example you can try this:

function just_a_test()
{
    call_user_func(array($this,'insert_coupon_codes'));
}

function insert_coupon_codes($post_array = array(), $primary_key = null)
{
    echo "Just a test";
    die();
    //Your code here
}

The problem in callbacks is that there is no error displaying when something goes wrong. So for example if you have

call_user_func(array($this,'test2'));

test2 function does not exist. But there is no error anywhere.

If everything goes fine with this, you can simply debug your insert/update with a simply hack.

In grocery CRUD the insert/update/delete is an ajax call, so to debug your project, you have to debug it with the firefox firebug. You can have your var_dump or print_r and see the ajax call response from your firebug. If you are not familiar with how to use firebug, I have a little hacking solution for the debug.

Simply go to your add or edit form and disable all the javascripts (You can download Web Developer for firefox and then click Disable>Disable Javascript>All Javascript). Then if you refresh the form add or edit and push submit, there will be the ajax request in a view. So there you can see your var_dump or print_r.

Still grocery CRUD doesn't support debugging for callbacks so I think its a good solution for now. Beside this for debugging without hacking you can always easily have the log_message function of codeigniter. For more you can see at http://ellislab.com/codeigniter/user-guide/general/errors.html

John Skoumbourdis
  • 3,041
  • 28
  • 34
  • Hi John, I'm very interested in debugging the SQL. Could you explain the second paragraph in more depth? I've tried these steps and I'm getting a box containing a json with {success:true, success_message: your data has been stored, and more fields} but I can't see any SQL. Where should it be? – voghDev May 05 '15 at 18:26