phpcodeignitercodeigniter-4

How to create and load new helper in CodeIgniter 4


i want to create new function in helper, but it still failed : Call to undefined function

i save my helper at app/Helper/Text_helper.php using namespace App\Helpers; and load helpers on BaseController using protected $helpers = ['text'];

Reference : https://codeigniter4.github.io/userguide/general/helpers.html#extending-helpers but it's still not working


Solution

  • It's not mentioned in documents but remember to add a suffix _helper to filename of your helper otherwise it will not work in codeigniter 4.

    For example if you have created a helper xxx.php, change it to xxx_helper.php.

    To load a helper you can use helper function (Like: helper('xxx.php');) or add it to $helpers array that is an protected property in BaseController