Welcome Guest, Not a member yet? Register   Sign In
helper callbacks
#1

[eluser]cmarra[/eluser]
Hello, but how can I do to execute a callback in a helper, for example

$ CI = & get_instance ();

$ Str = preg_replace_callback ('/(.)/', array ($ CI, "convert_accented_characters"), $ str);

Now "convert_accented_characters" is another method that is in the same helper but I generates the following error:

PHP Notice: in file application / helpers / my_helper.php on line 76: preg_replace_callback () [function.preg-replace-<a href='function.preg-replace-callback'> callback </ a>]: Requires argument 2 , 'Array', to be a valid callback

If we move these two methods directly in the controller does it all!

How can I fix?
#2

[eluser]cmarra[/eluser]
help brothers! Wink
#3

[eluser]mddd[/eluser]
The way you are doing it now, you are defining the callback to be $CI->convert_accented_characters().
That not correct. Functions defined in helpers are not methods of the $CI object. They are just plain functions.
So my guess is, it would work if you write:
Code:
$str = preg_replace_callback (’/(.)/’, “convert_accented_characters”, $str);
#4

[eluser]cmarra[/eluser]
excellent, you were right everything works ... thanks!
but practically wrong, because the passavao twice the subject of CodeIgniter?




Theme © iAndrew 2016 - Forum software by © MyBB