Debugging Grocery_CRUD callbacks

I saw a lot of people citing the use of call_user_func() to debug problems in the Grocery_CRUD , but unfortunately no one came off with a complete example to actually use it as if it were calling the test function [just_a_test()] in The controller example of what I'm trying to detect is here .

I can not understand where we call it

  • just_a_test() ,
  • how can we pass the desired parameters using call_user_func(array($this,'insert_coupon_codes')); when the pair is not passed to just_a_test() ?
  • how will insert_coupon_codes work to get the desired parameter?
+4
source share
1 answer

Grocery CRUD automatically adds parameters from the library. You cannot (still in version 1.1.8) add additional parameters in a callback.

Update: In the latest version of Grocery CRUD you can now pass as many parameters as you need. This is the functionality offered by PHP from PHP version 5.4 or later. More specifically, with the use keyword. If you have a callback_after_insert : usually you will use it like this:

 $crud->callback_after_insert(function ($post_array,$primary_key) { // Your code here }); 

From PHP 5.4 and later, you can add additional parameters with use so that, for example, you can:

 $my_variable = 'test'; $another_variable = 'hello'; $crud->callback_after_insert(function ($post_array,$primary_key) use ($my_variable, $another_variable) { // Now you can use the variables $my_variable and $another_variable at your callback }); 
+1
source

Source: https://habr.com/ru/post/1386028/


All Articles