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

Has ModuleDefinitionInterface interface changed in phalcon 2.0?

Using the dev-tools 1.3.3 to generate a skeleton project of type=modules I get the following error -

Fatal error: Declaration of Project\Frontend\Module::registerAutoloaders() must be compatible with Phalcon\Mvc\ModuleDefinitionInterface::registerAutoloaders(Phalcon\DiInterface $dependencyInjector = NULL) in /Users/ilongley/development/phoenix/apps/frontend/Module.php

I am running phalcon 2.0

In Module.php if I remove "implements ModuleDefinitionInterface" from the class declaration everything works fine.

Is there something I should be aware of?

Many thanks!



6.6k

The signature of the methods has changed a bit:

public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = null)
{
    //...
}

public function registerServices(\Phalcon\DiInterface $dependencyInjector)
{
    //...
}

dev-tools are not updated yet to support Phalcon 2.



2.6k
edited Nov '14

With that in mind then do you see anything wrong with the way the registerAutoloaders method is called in Module.php that could give rise to this error?

public function registerAutoloaders()
{
    $loader = new Loader();

    $loader->registerNamespaces(array(
        'Project\Frontend\Controllers' => __DIR__ . '/controllers/',
        'Project\Frontend\Models' => __DIR__ . '/models/',
    ));

    $loader->register();
}


6.6k

I think this should work:

public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = null) // <- here it is
{
    $loader = new Loader();

    $loader->registerNamespaces(array(
        'Project\Frontend\Controllers' => __DIR__ . '/controllers/',
        'Project\Frontend\Models' => __DIR__ . '/models/',
    ));

    $loader->register();
}


2.6k

Unfortunately that won't work. I'll take a look around some of the 2.0 projects in gihub to see if I can find out more. If I work it out I'll update this post ;-)



132

Hi guys, migrating big multi module multi domain project in our company to Phalcon 2. This is still an issue. Any idease or suggestions? Thanx



171
edited May '15

Same error here(from the php error log file):

PHP Fatal error: Declaration of Xxx\Frontend\Module::registerAutoloaders() must be compatible with Phalcon\Mvc\ModuleDefinitionInterface::registerAutoloaders(Phalcon\DiInterface $dependencyInjector = NULL) in c:\xxxpath\apps\frontend\Module.php on line 12

And the code in Module.php were like:

public function registerAutoloaders() { //..... }

public function registerServices($di) { //..... }

My Solution: As indicated in the error log, after the code were changed like below, it works again:

public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = NULL) { //..... }

public function registerServices(\Phalcon\DiInterface $dependencyInjector = NULL) { //........... }

Notes: As I tested, the first backslash can not be ignored, i.e

registerServices(\Phalcon\DiInterface $dependencyInjector = NULL)

works, but

registerServices(Phalcon\DiInterface $dependencyInjector = NULL)

does not.

Btw, that's the only hurdle encountered during the process of upgrading from 1.3 to 2.0.