Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

dynamic registration namespaces

Hello, i need dynamically register new library in controller. I would like to include a new library with a one new namespace, but with multiple files. How can I do that?

I have to do in the controller, because the configuration of the library is stored in the database.

Please help.



64.3k
Accepted
answer

i n module.php or application.php

$loader = new Loader();

$loader->registerNamespaces([
'MYAPP\Plugins' => '/var/www/myapp/Plugins/
]);

$loader->register();

inside /var/www/myapp/Plugins/ you can have folders and files, but you have to keep the concept

if you have file : /var/www/myapp/Plugins/Auth/Users.php this file has to be with namespace MYAPP\Plugins\Auth and class name has to be Users

keep in mind for small - big letters, you can check the docs for namespace includes