Loading helper before controller |
What is a good way to load a helper before the controllers run. I am trying to use a function in a helper file inside my controller __construct() function and I am autoloading them in the basecontroller right now but they are not available when __construct() is ran. What would be the best method of making sure the helper is available from within a controllers __construct()?
Thanks.
I want this but my Perm class uses a function in an auto-loaded helper file so this doesn't work.
PHP Code: class AdminBaseController extends \App\Controllers\BaseController However this works but it requires calling the function at the start every every public controller PHP Code: class AdminBaseController extends \App\Controllers\BaseController
Don't know exactly why this is (haven't looked in the code itself), but you can use an initController method instead of __construct to do what you want.
PHP Code: public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) (08-27-2020, 01:27 PM)jreklund Wrote: Don't know exactly why this is (haven't looked in the code itself), but you can use an initController method instead of __construct to do what you want.Thank you I think that is working now I actually have it inside a custom admin adminbasecontroller that extends the default basecontroller and it looks to be working from that. PHP Code: class AdminBaseController extends \App\Controllers\BaseController PHP Code: public function __construct() This code are unnecessary, in case you are only doing just that.
You could also place it in common.php
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Is this a good way to control before and after actions in CI4?
PHP Code: private function beforeRequest() And my initController looks like that; PHP Code: public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
I think what you want there are controller filters.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |