⚠ 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

how to use a personal helper in callback_column



Kleenex

Kleenex
  • profile picture
  • Member

Posted 18 November 2014 - 20:42 PM

Hi!

I have this problem, I want to show number in a column as currency euro.

so, everything goes fine if inside the controller i put this:

    public function _formattaEURO($num) {
    $eu = number_format($num, 2, ',', '.');
    return "€ ".$eu;    
    } 

I can use this function inside callback_column:

$crud->callback_column('Prezzo_acquisto', array($this, '_formattaEURO')); 

...since I have to use very often this function, I'd like save it in a personal helper stored in application/helper

 

this is the helper, named 'euro_helper.php':

<?php
if(!function_exists('euro'))
{
    function euro($num) {
    $eu = number_format($num, 2, ',', '.');
    return "€ ".$eu;   
    }
}

in the controller I load it in this way:

$this->load->helper('euro'); 

and I believed that this was ok to use it in callback_column, like this:

$crud->callback_column('Prezzo_acquisto', array($this, 'euro')); 

...but this is what I get:

 

 

A PHP Error was encountered

Severity: Warning

Message: call_user_func() expects parameter 1 to be a valid callback, class 'articoli' does not have a method 'euro'

Filename: libraries/Grocery_CRUD.php

Line Number: 1757

 

 

So, I don't know how I can use a personal helper inside callback_column.

Thanks a lot for any reply ;-)