Welcome Guest, Not a member yet? Register   Sign In
How to autoload helper functions in CodeIgniter 4?
#1

I recently downloaded CodeIgniter 4 from their official GitHub repository and noticed significant changes compared to CodeIgniter 3. I intend to utilize the base_url() function in my views, which requires loading the URL helper. In CodeIgniter 3, I used to autoload it in the config/autoload.php file. However, in CodeIgniter 4, the structure of the config/autoload.php file has been completely revamped, and I find it quite confusing.

To continue using the base_url() function in your views within CodeIgniter 4, you can add the following code to the constructor of your controller: helper('url');

If anyone familiar with CodeIgniter 4 knows how to autoload helper functions like url by modifying the config/autoload.php file, I would greatly appreciate your guidance.
Reply
#2

Quote:The URL helper is always loaded so you do not need to load it yourself.
https://codeigniter4.github.io/CodeIgnit...g-a-helper

Quote:If you find that you need a particular helper globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the app/Config/Autoload.php file and adding the helper to the $helpers property.
https://codeigniter4.github.io/CodeIgnit...ng-helpers
Reply
#3

@DerauKamyar Excuse me, but are you a real human?
Your answer seems correct at first glance, but in fact it is not correct and confuses the uninitiated..
Reply
#4

Almost sound like AI wrote it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

It seems to me that recently there have been more and more posts like this one, seemingly polite explanations but incorrect.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB