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

Module definition path '../apps/frontend/FrontendModule.php' does not exist

My index file looks as below;

error_reporting(E_ALL);
use Phalcon\Mvc\Router,
Phalcon\Mvc\Application,
Phalcon\DI\FactoryDefault;

$di = new FactoryDefault();

//Specify routes for modules
$di->set('router', function () {

$router = new Router();

$router->setDefaultModule("frontend");

$router->setDefaultNamespace('Project\Frontend\Controllers');

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

return $router;
    });
try {

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

// Register the installed modules
$application->registerModules(
    array(
        'frontend' => array(
            'className' => 'Project\Frontend\FrontendModule',
            'path'      => '../apps/frontend/FrontendModule.php',
        ),
        'backend'  => array(
            'className' => 'Project\backend\BackendModule',
            'path'      => '../apps/backend/BackendModule.php',
        )
    )
);

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

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


51.2k
Accepted
answer

try to use _ DIR _.'/../apps/frontend/FrontendModule.php',

edited Feb '15

Thanks alot. Your are a star. This Does.

However I get to this error;

Project\Frontend\Controllers\IndexController handler class cannot be loaded

My controller has the namespace as below. <?php namespace Project\Frontend\Controllers;

I have registered the namespace in module class as shown; public function registerAutoloaders() { $loader = new Loader(); $loader->registerNamespaces( array( 'Project\Frontend\Controllers' => '../apps/frontend/controllers/', 'Project\Frontend\Models' => '../apps/frontend/models/', ) ); $loader->register(); }

Is there something I should do in the index file for this to work? thanks



51.2k

Again, _ DIR _ maybe ? :)

public function registerAutoloaders() { 

  $loader = new Loader(); 
  $loader->registerNamespaces( array( 
      'Project\Frontend\Controllers' => __DIR__.'/../apps/frontend/controllers/', // IF THIS IS THE CORRECT PATH !
      'Project\Frontend\Models' => __DIR__'/../apps/frontend/models/', 
  ) );

  $loader->register(); 
}

I had added the directory path but doesn't seem to remove the error



51.2k

Can you provide us your directory structure ? You can do that quickly by using the tree command in your project folder

sure,

├───app │ ├───backend │ │ ├───controllers │ │ ├───models │ │ └───views │ │ ├───index │ │ └───layouts │ ├───cache │ ├───config │ ├───frontend │ ├───controllers │ ├───models │ └───views │ ├───index │ └───layouts │
└───public ├───css ├───files ├───img ├───js └───temp

On Wed, Feb 18, 2015 at 3:11 PM, Calin Rada [email protected] wrote:



51.2k

RTry this

public function registerAutoloaders() { 

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

  $loader->register(); 
}
edited Feb '15

I have managed to eliminate that error by removing the loader register class function content from the module class and registering all namespace within the index file.

now working on this error; - Service 'view' was not found in the dependency injection container. if you have a quick fix you can shot it my way:-)