how to load the helper(url) automatically in CI4? |
I want to use url function in global,
helper('url'); it is very easy in CI3, but I don't know how to load it automatically in CI4
Did you read the CI4 user guide?
https://bcit-ci.github.io/CodeIgniter4/h...his-helper
Simplest method currently is to have a BaseController that loads it up. It can be done something like:
Code: class BaseController extends CodeIgniter\Controller This is a little more work up front, but most projects will see you using a base controller or two anyway.
it doesn't work. I want to use site_url(''), in all the Controllers and views.thanks
Load the helper on BaseController, like this:
Code: class BaseController extends CodeIgniter\Controller Other controllers should extend this. (11-10-2016, 06:48 PM)ridho Wrote: Load the helper on BaseController, like this: Thanks a lot, it work well now...
Doh! Sorry about that. In my example I was adding the helpers to the helpers array AFTER calling the parent constructor, when it would have needed to happen BEFORE calling the parent constructor.
Either way, ridho's solution is a bit simpler and works great, also! (11-09-2016, 08:12 PM)kilishan Wrote: Simplest method currently is to have a BaseController that loads it up. It can be done something like: I thing: Code: class BaseController extends CodeIgniter\Controller (11-09-2016, 08:12 PM)kilishan Wrote: Simplest method currently is to have a BaseController that loads it up. It can be done something like: Does it possible to load helper function through config/Autoload.php? |
Welcome Guest, Not a member yet? Register Sign In |