Hi!
i'm programming a web with backend access and API, and I want to use multi-module app with shared model.
I want acces api via:
- xxxx.com/api/controller/action/params
And access backend via:
- myweb.com/controller/action/params
My router file is:
<?php
use Phalcon\Mvc\Router;
$di->set('router', function () {
$router = new Router(false);
$router->removeExtraSlashes(true);
/*$router->setDefaultModule('backend');
$router->setDefaultController('index');
$router->setDefaultAction('index');*/
$router->add('/api/',[
'namespace' => 'MyModule\Api\Controllers',
'module' => 'api',
'controller' => 'index',
'action' => 'index'
]);
$router->add('/api/:controller',[
'namespace' => 'MyModule\Api\Controllers',
'module' => 'api',
'controller' => 1,
'action' => 'index'
]);
$router->add('/api/:controller/:action',[
'namespace' => 'MyModule\Api\Controllers',
'module' => 'api',
'controller' => 1,
'action' => 2
]);
$router->add('/api/:controller/:action/:params',[
'namespace' => 'MyModule\Api\Controllers',
'module' => 'api',
'controller' => 1,
'action' => 2,
'params' => 3
]);
$router->add('/',[
'namespace' => 'MyModule\Backend\Controllers',
'module' => 'backend',
'controller' => 'index',
'action' => 'index'
]);
$router->add('/:controller',[
'namespace' => 'MyModule\Backend\Controllers',
'module' => 'backend',
'controller' => 1,
'action' => 'index'
]);
$router->add('/:controller/:action',[
'namespace' => 'MyModule\Backend\Controllers',
'module' => 'backend',
'controller' => 1,
'action' => 2
]);
$router->add('/:controller/:action/:params',[
'namespace' => 'MyModule\Backend\Controllers',
'module' => 'backend',
'controller' => 1,
'action' => 2,
'params' => 3
]);
return $router;
});
I only have problems with API access, in the log appears:
PHP Fatal error: Uncaught Phalcon\Mvc\Dispatcher\Exception: MyModule\Backend\Controllers\ApiController handler class cannot be loaded in C:\wamp\www\mynewapp\public\index.php:96
Stack trace:
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('MyModule\\Backend...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 C:\wamp\www\mynewapp\public\index.php(96): Phalcon\Mvc\Application->handle()
#3 C:\wamp\www\mynewapp\public\index.php(101): Application->main()
#4 {main}
thrown in C:\wamp\www\mynewapp\public\index.php on line 96
I'm using PHP7 and Nginx
What am I doing wrong?
Thank you very much in advance