Welcome Guest, Not a member yet? Register   Sign In
add_package_path() equivalent?
#1

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 {
    public function __construct()
    {
        parent::__construct();
        $this->load->add_package_pathAPPPATH "sites/" SITE_NAME);
    }





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 Smile
Reply
#2

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
Reply
#3

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 Sad
Reply
#4

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
Reply
#5

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.
Reply
#6

You may need to extend View class.
See https://github.com/codeigniter4/CodeIgni...#L190-L194
Reply




Theme © iAndrew 2016 - Forum software by © MyBB