4

I have seen many people referring to the usage of call_user_func() to debug the problems in a Grocery_CRUD callback, but unfortunately no one has come off with a complete example to actually how to use it like where to to place a call to the test function [just_a_test()] in the controller an example of what I am trying to discover is here.

I am unable to understand where do we call this

  1. just_a_test(),
  2. how are we able to pass on the desired parameters using call_user_func(array($this,'insert_coupon_codes')); when there are no para's being passed to the just_a_test()?
  3. how come the insert_coupon_codes will be able to get the desired para's?
Community
  • 1
  • 1
Tanver
  • 41
  • 1

1 Answers1

1

Grocery CRUD add the parameters automatically from the library. You are not able (till now at version 1.1.8) to add more parameters at your callback.

Update: At the latest version of Grocery CRUD now you CAN pass as many parameters as you need. This is a functionality that PHP is offering from version PHP 5.4 or later. More specifically with the use keyword. More specifically if you have the callback callback_after_insert: usually you would use it like this:

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

From PHP 5.4 version and later you can add more parameters with the use so for example you could have:

$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
});
John Skoumbourdis
  • 3,041
  • 28
  • 34