首先,对不起,我不会说英语。我使用Silex,我只想在用户有权访问应用程序的这一部分时才挂载ControllerProvider。 在app.php中,我有一个服务,它创建一个用户,他拥有所有可访问的模块。
$app['utilisateur'] = function() use ($app){
$utilisateurToken = UtilisateurController::getUserByToken($app['security.token_storage']);
if ($utilisateurToken->isAnnonyme())
{
$utilisateur = $utilisateurToken;
$module_repository = new ModuleRepository($app['db_intranet_v3']);
$modules = $module_repository->find();
$utilisateur->addModules($modules);
}
else
{
$utilisateur = UtilisateurController::getUserByIdWithModules($app,$utilisateurToken->getId());
}
return $utilisateur;
};
然后,我手动安装每个模块' :
$app->mount('/exampleModule', new exampleModuleControllerProvider());
是否可以自动将模块安装在服务中?当我尝试时,我有一个错误:"无法生成指定路由的URL" exampleModule"因为这样的路线不存在。" 你能帮帮我吗?
答案 0 :(得分:0)
我相信解决方案非常简单。该错误告诉您它找不到名为exampleModule
的路由,因此我们应该给他一个具有该名称的路由。
我们可以使用bind
定义命名路线,因此您的路线应以这种方式安装:
$app->mount('/exampleModule', new exampleModuleControllerProvider())->bind('exampleModule');
可在this page in the documentation找到更多信息。