![]() |
my controller fails to find helper function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: my controller fails to find helper function (/showthread.php?tid=92865) |
my controller fails to find helper function - PaulC - 05-07-2025 Hi Team, I love the new error interface - great job! Its helping me to upgrade my ci3 to ci 4.6.0 Latest snag is my controller which extends BaseController cannot find the validation function: - the function is 'is_valid_level' which is defined in a Helper myvalidate_helper.php - the myvalidate helper is loaded (I think) by adding to the $helpers array in the BaseController (I can see it in the list of files). - ci3 call was PHP Code: if (!is_valid_level($level3)) { .... PHP Code: if (!myvalidate(is_valid_level($level3))) { .... Clearly I have misunderstood something important, so could someone explain what I have got wrong please? Thx Paul RE: my controller fails to find helper function - grimpirate - 05-07-2025 Your helper is called myvalidate_helper, but the function you define inside it (I'm assuming) is named is_valid_level. There is no myvalidate function. There was no need to change your ci3 code. If you want to be sure the helper is being loaded do the following: PHP Code: helper('myvalidate'); RE: my controller fails to find helper function - PaulC - 05-07-2025 (Yesterday, 07:25 AM)grimpirate Wrote: Your helper is called myvalidate_helper, but the function you define inside it (I'm assuming) is named is_valid_level. There is no myvalidate function. There was no need to change your ci3 code. If you want to be sure the helper is being loaded do the following: Thx for reply. I have reverted to the original code which tries to run a function called is_valid_level in the helper myvalidate. The error is very similar: Call to undefined function App\Controllers\is_valid_level() I then tried calling the helper just before the statement and it made no difference. So, I have checked the BaseController array is correct, and my Controller extends BaseController, so it doesn't appear to be working? Any other things to check please? TIA Paul RE: my controller fails to find helper function - paulbalandan - 05-07-2025 Where did you save the myvalidate_helper.php file? Make sure it is on app/Helpers/ directory. RE: my controller fails to find helper function - grimpirate - 05-07-2025 Post BaseController.php and myvalidate_helper.php source. Is myvalidate_helper.php located in app/Helpers/myvalidate_helper.php? RE: my controller fails to find helper function - PaulC - 05-07-2025 PHP Code: <?php RE: my controller fails to find helper function - paulbalandan - 05-07-2025 Ok got it. In your use statements, just add this line. use function App\Helpers\is_valid_level; RE: my controller fails to find helper function - InsiteFX - 05-07-2025 Helpers can also be added to the app/Config/Autoload.php RE: my controller fails to find helper function - PaulC - 05-08-2025 (8 hours ago)paulbalandan Wrote: Ok got it. In your use statements, just add this line. Thx for this. Slightly dismayed at the implication though! Do I have to list all the functions in our helpers with individual use statements? This seems to defeat the autoloading intention, and I don't think this requirement is highlighted in the docs I have read to date? PS I tried listing the helpers in the Autoload.php file and that didn't make any difference. Regards, Paul I just tried adding the use statement and still get Call to undefined function App\Controllers\is_valid_level() |