my controller fails to find helper function |
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
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'); (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
Where did you save the myvalidate_helper.php file? Make sure it is on app/Helpers/ directory.
Post BaseController.php and myvalidate_helper.php source. Is myvalidate_helper.php located in app/Helpers/myvalidate_helper.php?
PHP Code: <?php
Ok got it. In your use statements, just add this line.
use function App\Helpers\is_valid_level;
Helpers can also be added to the app/Config/Autoload.php
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(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() |
Welcome Guest, Not a member yet? Register Sign In |