⚠ 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 forum is read-only and soon will be archived. ⚠


how to use a personal helper in callback_column

callback_column helpers

  • Please log in to reply
No replies to this topic

#1 Kleenex

Kleenex

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 18 November 2014 - 08:39 PM

Hi!

I have this problem, I want to show some numbers 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.

I'd prefer use a separate helper to call inside the controller rather than write the public function in every controller

 

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 ;-)







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users