lemoeb Posted May 11, 2018 Share Posted May 11, 2018 (edited) I'm writing a custom module for prestaShop.I was able to correctly display a new field in the list of customers in the BackEnd section.Now I would need to insert a callback for a specific field in this table but when I try to use it I get an error.PrestaShop tells me that the callback function called up is not available in the AdminController.Attached to this message is the complete code of my module. The callback i want to use is : public function printAsiStatusIcon($value, $customer) { return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=AdminCustomers&id_customer=' .(int)$customer['id_customer'].'&changeAsiStatus&token='.Tools::getAdminTokenLite('AdminCustomers')).'"> '.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>'). '</a>'; } and called in this section of crsociasi.php : foreach ($params['fields'] as $key => $value){ if ($key!='email'){ $newParam[$key]=$value; } else{ $newParam[$key]=$value; $newParam['cardAsi'] = array( 'title' => 'cardAsi', 'align' => 'center', 'search' => true, 'havingFilter' => true, 'filter_key' => 'asi!cardAsi' ); $newParam['statoAsi'] = array( 'title' => 'Stato Asi', 'align' => 'center', 'callback' => 'printAsiStatusIcon' ); } } $params['fields']=$newParam; The error i receive from PS is : Quote Warning alla linea 335 nel file ...............classes/helper/HelperList.php [2] call_user_func_array() expects parameter 1 to be a valid callback, class 'AdminCustomersController' does not have a method 'printAsiStatusIcon' Can anyone help me? Thank's in advance crsociasi.zip Edited May 11, 2018 by lemoeb (see edit history) Link to comment Share on other sites More sharing options...
Mantovani Maurizio Posted July 4, 2018 Share Posted July 4, 2018 On 11/5/2018 at 2:32 PM, lemoeb said: I'm writing a custom module for prestaShop.I was able to correctly display a new field in the list of customers in the BackEnd section.Now I would need to insert a callback for a specific field in this table but when I try to use it I get an error.PrestaShop tells me that the callback function called up is not available in the AdminController.Attached to this message is the complete code of my module. The callback i want to use is : public function printAsiStatusIcon($value, $customer) { return '<a class="list-action-enable '.($value ? 'action-enabled' : 'action-disabled').'" href="index.php?'.htmlspecialchars('tab=AdminCustomers&id_customer=' .(int)$customer['id_customer'].'&changeAsiStatus&token='.Tools::getAdminTokenLite('AdminCustomers')).'"> '.($value ? '<i class="icon-check"></i>' : '<i class="icon-remove"></i>'). '</a>'; } and called in this section of crsociasi.php : foreach ($params['fields'] as $key => $value){ if ($key!='email'){ $newParam[$key]=$value; } else{ $newParam[$key]=$value; $newParam['cardAsi'] = array( 'title' => 'cardAsi', 'align' => 'center', 'search' => true, 'havingFilter' => true, 'filter_key' => 'asi!cardAsi' ); $newParam['statoAsi'] = array( 'title' => 'Stato Asi', 'align' => 'center', 'callback' => 'printAsiStatusIcon' ); } } $params['fields']=$newParam; The error i receive from PS is : Can anyone help me? Thank's in advance crsociasi.zip Same problem.... any help guys? Link to comment Share on other sites More sharing options...
Estian Posted August 4, 2020 Share Posted August 4, 2020 (edited) I believe you have to also specify the callback object. $newParam['statoAsi'] = array( 'title' => 'Stato Asi', 'align' => 'center', 'callback' => 'printAsiStatusIcon', 'callback_object => $this ); Something like that. What I'm wondering is how parameters are sent to it. I guess it just receives the value that correlates with it from the $db SELECTED results. Edited August 4, 2020 by Estian (see edit history) Link to comment Share on other sites More sharing options...
Nico Senentz Posted May 19, 2021 Share Posted May 19, 2021 In fact, it's : $newParam['statoAsi'] = array( ..... 'callback' => 'printAsiStatusIcon', 'callback_object => Module::getInstanceByName($this->name), ); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now