We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to add new module in multi module skeleton

I have generated a project with Devtool and has multi modules skeleton . By default it has: frontend and Cli module. Now i want to add more module name: backend. How can I do and what config and services file I have to edit please ?

Well , i do this manualy all the time

  1. Open Modules.php and add the module . Example Code :
$application->registerModules([
    'Frontend' => [
        'className' => 'Frontend\Module',
        'path'      => __DIR__ . '/../apps/Frontend/Module.php'
    ],
    // new module
    'Backend' => [
        'className' => 'Backend\Module',
        'path'      => __DIR__ . '/../apps/Backend/Module.php'
    ],
]);
  1. in app folder duplicate the frontend folder and rename to Backend
  2. in the backend folder edit the Module.php and rename th namespace to Backend. Example:
<?php
// here
namespace Backend;

use Phalcon\Loader,
    Phalcon\Mvc\View,
    Phalcon\Config\Adapter\Ini,
    Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter,
    Phalcon\Mvc\ModuleDefinitionInterface;

class Module
{
  1. also in the Module.php you will have to rename the registered namespaces. Example :

$loader->registerNamespaces([
      'Backend\Controllers'  => __DIR__ . '/controllers/',
      'Backend\Models'       => __DIR__ . '/models/'
    ]);
  1. now for the controllers / models you will have to rename all the namespaces. Example:
namespace Backend\Controllers;
namespace Backend\Models;