Thursday, March 17, 2022

[FIXED] I would like to prefix my CakePHP plugins namespace with my name

Issue

I have a plugin I am calling AdminLTE, and I have other plugins that rely on AdminLTE, so I would like to prefix all my AdminLTE plugins with AdminLTE

For instance

namespace AdminLTE\Calendar\Controller;

Where Calendar is the name of the actual plugin

How would I go about extending the CakePHP Autoloader to be able to find a class like below... And if possible, can I create that autoloader in a plugin?

namespace AdminLTE\Calendar\Controller;

use App\Controller\AppController as BaseController;

class AppController extends BaseController
{
}

Solution

How would I go about extending the CakePHP Autoloader...

Something like this in composer.json:

"autoload": {
    "psr-4": {
        "App\\": "src/",
        "AdminLTE\\Calendar\\": "plugins/Calendar/src/",
        "AdminLTE\\": "plugins/AdminLTE/src/"
    }
}

https://book.cakephp.org/3.0/en/development/configuration.html#additional-class-paths

And if possible, can I create that autoloader in a plugin?

If your plugins have composer.json then it should be possible.



Answered By - bancer

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.