Welcome Guest, Not a member yet? Register   Sign In
How to call helper function from Controller's Constructor?
#1

Anyone know how to call helper function from Controller's Constructor?, iIve tried and thrown an error, tried adding $this->thefunction() but it also produce an error since this will make complication with function inside controller. Currently I just put everything inside among functions instead constructor but hope there's a way to solve this  Huh
Reply
#2

If you loaded your helper then you can call it's function only with name - thefunction();
Reply
#3

(This post was last modified: 11-11-2020, 04:56 AM by munggaran.)

(11-11-2020, 02:01 AM)T.O.M. Wrote: If you loaded your helper then you can call it's function only with name - thefunction();
I loaded helper in basecontroller so all controller will have the helper, it works whenever I call thefunction() inside index() or other_function(), but if I try to call from __constructor it will raise an error  Sad
Reply
#4

(This post was last modified: 11-11-2020, 07:02 AM by T.O.M..)

In BaseController constructor is initController() method (not __constructor()).
So your __constructor() is called earlier then BaseController::initController() and helpers are not loaded yet.
You can try to load helper manually in your constructor right before call its method with
PHP Code:
helper('your_helper'); 
Reply
#5

(11-11-2020, 06:58 AM)T.O.M. Wrote: In BaseController constructor is initController() method (not __constructor()).
So your __constructor() is called earlier then BaseController::initController() and helpers are not loaded yet.
You can try to load helper manually in your constructor right before call its method with
PHP Code:
helper('your_helper'); 


ahhh, now it's working Smile thanks mate!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB