Welcome Guest, Not a member yet? Register   Sign In
CI4 autoloading with auto fallback to "core" implentation
#1

Hello CI Experts, 

we are using CI3 since years and love this lightwight framework!  Heart
Now we want to migrate our projects to CI4.
Unlikely we are a little bit lost how to setup the namespaces and manage our application in the best way with CI4 autoloading logic.  Confused

What we currently have the following structure in CI3 (with extended CI_Loader) and now want to move to CI4:


Code:
Core
|- Controllers
|- Views
|- Languages
Customers
|-Customer_A
|  |-Controllers
|  |-Views
|  |-Languages
|-Customer_B
|  |-Controllers
|  |-Views
|  |-Languages


We have common core features like login, profile etc. which are used for all customers.

After the user is authenticated, we our URLs look like: /app/Customer_A/controller/method or /app/Customer_B/controller/method

What we need:

1. All Controllers can extend the Core Controller to reuse or overwrite methods.

2. If a customer specific View file exists load this, otherwise load the View file from the core directory.

3. Load the core Language file at first, but if a customer specific Language file exists load this too and extends / overwrite the core.


It’s important that there is always a fallback to the core functionality for Controllers, Views and Languages. 
So if there is no customer specific implementation load the core implentation instead!

We extended the CI3 autoloader to manage this, without adding routes or throwing exceptions in case if the customer files does not exists.
We ensure that the Core Controllers, Views and Languages exists.

How to manage this automatic fallback to the Core implementation in CI4?
Is there an easy Best Practice with namespaces and / or the new CI4 autoloading logic?

I already read the CI4 documentation with the Code Modules logic, but this does not include the auto fallback to the core implentation.
This is our big adventage to just overwrite / extend the core for certain customers, if not use the core instead.

Please ask if something confusing, I'll try to give you examples. 

Thanks in advance for your ideas and help  Big Grin
Reply
#2

Namespace structure would look something like this.

Code:
Core                           app
|- Controllers                 |- Controllers
|- Views                       |- Views
|- Languages                   |- Languages
Customers                      Customers      (namespace Customers)
|-Customer_A                   |- CustomerA   (namespace Customers/CustomerA)
|  |-Controllers               |- Controllers (namespace Customers/CustomA/Controllers)
|  |-Views                     |- Views       (namespace Customers/CustomA/Views)
|  |-Languages                 |- Languages   (namespace Customers/CustomA/Languages)
|-Customer_B                   |- CustomerB   (namespace Customers/CustomerB)
|  |-Controllers               |- Controllers (namespace Customers/CustomB/Controllers)
|  |-Views                     |- Views       (namespace Customers/CustomB/Views)
|  |-Languages                 |- Languages   (namespace Customers/CustomB/Languages)

As far as auto fallback this is something that you would need to write.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB