Zemit is a Multi-Module Phalcon Application using the MVC (model–view–controller) pattern. You can create your own module and extend the existing modules configured in Zemit Core. The module are configured within the default Configuration component injected into the DI of the bootstrap.
Zemit Bootstrap will read the module section of the configuration and then register the proper paths of the defined Module.php file as well as the default route.
Module Configuration
Zemit Core comes with some default modules. You can override or unset any of these of necessary.
Creating your own Module
Creating your own module is pretty simple. Let's say you want to create your own module named Custom.
Recommended file structure
This suggested structure below is the standard used by Zemit Core. By using this standardized structure, you won't have to override getViewsDir() and getNamespaces() methods of the Zemit\Mvc\Module class to fit your needs.
You will have to create a new Module file ./app/Modules/Custom/Modules.php which will extend from the \Zemit\Mvc\Module class.
// ./app/Modules/Custom/Modules.phpnamespaceApp\Modules\Custom;classModuleextends\Zemit\Mvc\Module{// put your module name herepublic $name ='custom';}
Add the custom module into the Configuration
// ./app/Bootstrap/Config.phpnamespaceApp\Bootstrap;classConfigextends\Zemit\Bootstrap\Config{publicfunction__construct($config = []) {parent::__construct([// ...'modules'=> [// New custom module, the key is the module name'custom'=> ['className'=> APP_NAMESPACE .'\\Modules\\Custom\\Module','path'=> APP_PATH .'/Modules/Custom/Module.php', ], ],// ... ]);if (!empty($config)) {$this->merge(new\Phalcon\Config($config)); } }}
Removing a default Zemit Module
Since Zemit Core define some modules by default, if you would like to remove these, you will have to remove them from the Configuration before they are registered. In order to achieve this, here is an example by overriding the Config and unsetting the modules variables you'd like to remove.
// ./app/Bootstrap/Config.phpnamespaceApp\Bootstrap;classConfigextends\Zemit\Bootstrap\Config{publicfunction__construct($config = []) {parent::__construct([// ... ]);// Remove the module you want by unsetting the variableunset($this->modules->frontend);unset($this->modules->admin);unset($this->modules->api);unset($this->modules->cli);unset($this->modules->oauth2);if (!empty($config)) {$this->merge(new\Phalcon\Config($config)); } }}