Hy Friends!
我正在开发一个更大的项目,并希望使用多模块应用程序来存档我的目标。但我有路由问题。我总是得到以下网址错误(http://dev.local/backend/index/index):
无法加载Application \ Modules \ Frontend \ Controllers \ BackendController处理程序类
我的引导程序文件:
<?php
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Collection\Manager;
use Phalcon\Mvc\Router;
ini_set("display_errors", "on");
error_reporting(E_ALL);
$di = new FactoryDefault();
/**
* Router
*/
$di->set("router", function () {
$router = new Router(true);
$router->setDefaultModule('frontend');
return $router;
});
/**
* URI
*/
$di->set("url", function() {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri("/");
return $url;
});
/**
* MongoDB
*/
$di->set("mongo", function () {
$mongo = new MongoClient('mongodb://localhost:27017');
return $mongo->selectDB('iowling');
});
/**
* MongoDB Collection Manager
*/
$di->set("collectionManager", function() {
$manager = new Manager();
return $manager;
});
try {
$application = new \Phalcon\Mvc\Application($di);
$application->registerModules(array(
'frontend' => array(
'className' => \Application\Modules\Frontend\Module::class,
'path' => __DIR__ . '/../modules/frontend/Module.php'
),
'backend' => array(
'className' => \Application\Modules\Backend\Module::class,
'path' => __DIR__ . '/../modules/backend/Module.php'
)
));
$response = $application->handle();
$response->send();
} catch (Exception $e) {
echo $e->getMessage();
}
我的后端模块:
<?php
namespace Application\Modules\Backend {
use Phalcon\Loader;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\ModuleDefinitionInterface;
class Module implements ModuleDefinitionInterface
{
public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = null)
{
$loader = new Loader();
$loader->registerNamespaces(array(
'Application\Modules\Backend\Controllers' => __DIR__ . '/../backend/controllers/',
'Application\Modules\Backend\Collections' => __DIR__ . '/../backend/collections'
));
$loader->register();
}
public function registerServices(\Phalcon\DiInterface $dependencyInjector)
{
$dependencyInjector->set("dispatcher", function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace(
'Application\Modules\Backend\Controllers'
);
return $dispatcher;
});
}
}
}
我的前端模块
<?php
namespace Application\Modules\Frontend {
use Phalcon\Loader;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Mvc\View;
class Module implements ModuleDefinitionInterface
{
public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = null)
{
$loader = new Loader();
$loader->registerNamespaces(array(
'Application\Modules\Frontend\Controllers' => __DIR__ . '/../frontend/controllers/',
'Application\Modules\Frontend\Collections' => __DIR__ . '/../frontend/collections/'
));
$loader->register();
}
public function registerServices(\Phalcon\DiInterface $dependencyInjector)
{
$dependencyInjector->set("dispatcher", function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace(
'Application\Modules\Frontend\Controllers'
);
return $dispatcher;
});
$dependencyInjector->set("view", function () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(array(
'.volt' => function($view, $dependencyInjector) {
$volt = new View\Engine\Volt($view, $dependencyInjector);
$volt->setOptions(array(
"compiledPath" => __DIR__ . '/../../cache/',
'compileAlways' => true
));
return $volt;
}
));
return $view;
});
}
}
}
你们有什么想法我做错了吗?我真的很喜欢它。
THX!