⚠ 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. ⚠


[solved] how to use a personal helper in callback_column

callback_column helpers

  • Please log in to reply
2 replies to this topic

#1 Kleenex

Kleenex

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 18 November 2014 - 08:43 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 ;-)



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts

Posted 19 November 2014 - 09:13 AM

well my friend .. u dont need to use $this... for a function from helper

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

that dose the trick for the same ...

 

Happy GCing :)



#3 Kleenex

Kleenex

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 19 November 2014 - 10:46 AM

that works perfectly!

...it's a really happy GCing  :D

 

Thanks a lot, Amit







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users