Where to store common 'global' functions? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Where to store common 'global' functions? (/showthread.php?tid=74366) |
Where to store common 'global' functions? - bustersg - 09-16-2019 I have a bunch of functions on common.php (no class just pure functions) Now migration to CI4 framework, where should I park this bunch of functions? Some or most functions does interact with database. I saw 2 possibilities: /app/Libraries and /app/ThirdParty Where should I store them and how should I load them? Is it load via Autoload.php? RE: Where to store common 'global' functions? - kilishan - 09-16-2019 If you want them loaded all of the time, you can add them App/Common.php. If you want them to be available to load just when needed, treat them as a Helper. RE: Where to store common 'global' functions? - bustersg - 09-16-2019 (09-16-2019, 11:34 AM)kilishan Wrote: If you want them loaded all of the time, you can add them App/Common.php. You mean justĀ "Extending" Helpers? RE: Where to store common 'global' functions? - kilishan - 09-16-2019 (09-16-2019, 11:59 AM)bustersg Wrote:(09-16-2019, 11:34 AM)kilishan Wrote: If you want them loaded all of the time, you can add them App/Common.php. You only need to "extend" if they're the same name as another one. Create a new file for your own helpers. Based on your comment, we'll call it database_helper.php. Store this file at App/Helpers/database_helper.php. Then use [b]helper('database')[b] when you need to load them. Or autoload them per-controller. |