Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Custom function to access globally

I want to define a custom function and use that in Volts and contollers simulteniously. I tried this way

$di->set('en2bn', function ($input) {
    $bn_digits = array('০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯');
    $output = str_replace(range(0, 9), $bn_digits, $input);
    return $output;
});

and tried to access within controller this way

$this->en2bn(8);

And got error. Can you please advice me?



3.0k
Accepted
answer
edited Apr '15

Just create a seperate class where you have all your custom functions, instead of using $di->set()