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

Muliti Module Project Error

Hi guys, I'm having some issue on multimodule project on my screen it display an error

Fatal error: Declaration of ModuleFrontPage\Module::registerAutoloaders() must be compatible with Phalcon\Mvc\ModuleDefinitionInterface::registerAutoloaders(Phalcon\DiInterface $dependencyInjector = NULL) in /path/to/my/project/app/app-frontpage/Module.php on line 12

here is my Module.php in app/app-frontpage/Module.php

<?php

namespace ModuleFrontPage;

use \Phalcon\Loader;
use \Phalcon\Mvc\View;
use \Phalcon\DiInterface;
use \Phalcon\Mvc\Dispatcher;
use \Phalcon\Mvc\ModuleDefinitionInterface;

class Module implements ModuleDefinitionInterface
{
    /**
     * Register a specific autoloader for the module
     */
    public function registerAutoloaders(DiInterface $di)
    {
        $loader = new Loader();

        $loader->registerNamespaces(
            array(
                'ModuleFrontPage\Controllers' => '../app/app-frontpage/controllers/',
                'ModuleFrontPage\Models'      => '../app/app-frontpage/models/',
            )
        );

        $loader->register();
    }

    /**
     * Register specific services for the module
     */
    public function registerServices(DiInterface $di)
    {
        // Registering a dispatcher
        $di->set('dispatcher', function () {
            $dispatcher = new Dispatcher();
            $dispatcher->setDefaultNamespace("ModuleFrontPage\Controllers");
            return $dispatcher;
        });

        // Registering the view component
        $di->set('view', function () {
            $view = new View();
            $view->setViewsDir('../app/app-frontpage/views/');
            return $view;
        });
    }
}

and my index.php

<?php

error_reporting(E_ALL);
define('APP_PATH', realpath('..'));

use \Phalcon\Mvc\Router;
use \Phalcon\Mvc\Application;
use \Phalcon\DI\FactoryDefault;
use \Phalcon\Debug;

//(new Debug())->listen();

$di = new FactoryDefault();

try {

    $config = require(APP_PATH.'/app/config/config.php');
    require(APP_PATH.'/app/config/loader.php');
    require(APP_PATH.'/app/config/services.php');
    require(APP_PATH.'/app/config/router.php');

    // Create an application
    $application = new Application($di);

    // Register the installed modules
    $application->registerModules(
        array(
                'AppFrontPage' => array(
                    'className' => 'ModuleFrontPage\Module',
                    'path'      => APP_PATH.'/app/app-frontpage/Module.php'
                )
            )
    );

    // Handle the request
    echo $application->handle()->getContent();

} catch (\Exception $e) {
    echo $e->getMessage();
}

router.php

<?php

//Registering a router
$di->set('router', function(){

    $router = new \Phalcon\Mvc\Router();

    $router->setDefaultModule("AppFrontPage'");

    $router->add('/', array(
        'module' => 'AppFrontPage',
        'controller' => 'index',
        'action' => 'index',
    ));

    return $router;
});


85.5k
Accepted
answer

public function registerAutoloaders(\Phalcon\DiInterface $di = null){
//bla bla bla 
}

add = null