add_package_path() equivalent? |
Hello, new to the forums.
The company I work for currently uses CodeIgniter 3.x. One of our projects is somewhat of a whitelabel with a shared code base. We currently use add_package_path() to load views/helpers/configs/constants/etc. on a per whitelabel (site) basis. You get the picture. We extend CI_Controller like so: PHP Code: class US_Controller extends CI_Controller { In this example, when loading a view, it first looks for the view in the 'sites/' path and loads the view if it exists there. If not found, it looks for the view in the normal views/ directory and loads that as the fallback (like a global/common view). TLDR: Is anything like this possible in CodeIgniter 4? I realize there are namespaces, but we're looking to just Code: echo view('viewFile') as usual without specifying anyting extra/special every time. Is there a similar way to extend the CI loader? Anything? Just now starting to dive into CI4, so pardon my ignorance in advance ![]()
You could probably do a lightweight extension of the view() function that would handle this. There are already good resources in FileLoader for searching across all namespaces (or you could even just specify one) and still fall back to app/Views
It's been almost 2 years since I asked about this, but we ended up sticking with CI 3 for the time being. I think it's time to migrate to 4.
I realize a lot has changed since then, if someone could point me in the right direction, it would be greatly appreciated. I'm not all that familiar with the CI core ![]()
See
- https://github.com/codeigniter4/CodeIgni....php#L1080 - https://github.com/codeigniter4/CodeIgni...ocator.php You can define your own `view()` in app/Common.php: https://github.com/codeigniter4/CodeIgni...Common.php
Thank you for the reply.
Oddly enough, those are the first two places I looked, but admittedly, I have no idea where to go from there.
You may need to extend View class.
See https://github.com/codeigniter4/CodeIgni...#L190-L194 |
Welcome Guest, Not a member yet? Register Sign In |