⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callback_field - parameters



gingebaker

gingebaker
  • profile picture
  • Member

Posted 02 February 2012 - 12:06 PM

Hello

I am working with callback_field function. As I can see in the grocery crud library class there are different params that will go to the callback function.

1.1.8 version: libraries/grocery_crud.php
[b]Line 1667 (for edit callbacks)[/b]
$field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key);

[b]Line 1624 (for add callbacks)[/b]
$field_input->input = call_user_func($this->callback_add_field[$field->field_name]);


I took the callback_field function for defining some special textfields (add special css classes and so on). I often needed the same callback function for more than one field so its redundant to define always the same functions only with other fieldnames.

I came up with following solution. I am extending the grocery_CRUD class, overriding the functions get_add_input_fields() and get_edit_input_fields().
[b]Then I changed the callback "call" in the get_add_input_fields() to:[/b]
$field_input->input = call_user_func($this->callback_add_field[$field->field_name],$field_info);

[i]wich is adding the field_info data as param. Then I have more option in my callback function.[/i]

[b]and the "call" in and get_edit_input_fields() to:[/b]
$field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_info, $field_value, $primary_key);

[i]wich also adds the field_info array, plus the $field_value and the primary key wich were already present.[/i]

Now I can make a nice callback function for edit and add callbacks, where I have all my needed info in the params.
[b]Example:[/b]
[u]The call:[/u]
$crud->callback_field($field,array($this,'callbackMakePricefield'));

[u]The Function:[/u]
public function callbackMakePricefield($field_info = false, $field_value = false, $primary_key = false) {
return '<input type="text" class="pricefield" value="" name="'..'" .$field_info->name.'"> &euro;';
}


I don´t know if I am missing some problems on that. But in my opinion this would be a nice decision to make the params of the edit and add callbacks more flexible.

By the way: [u]grocery crud is AMAZING!![/u]