0
我创建了一个名为@Module的注释类和一个命令GenerateModulesCommand。我想要的是找到具有@Module注释的所有控制器操作。检索具有特定注释的所有控制器操作 - Symfony2
例子:
/**
*
* @Module(name='sidebar', enabled=true')
*/
public function sidebarAction($name) {
$ape = new ArrayParamsExtension();
return $this->render('ModuleManagerBundle:Default:sidebar.html.twig', $ape->getArrayParams($name));
}
我希望能够看在@Module特定的属性(名称,启用,等等) 到目前为止,这是我从我的命令执行方法:
protected function execute(InputInterface $input, OutputInterface $output) {
$path = $this->getApplication()->getKernel()->locateResource('@ModuleManagerBundle');
$driver = new PHPDriver($path);
$classes = $driver->getAllClassNames();
foreach ($classes as $key => $class) {
$reader = new AnnotationReader();
$annotationReader = new CachedReader(
$reader, new ArrayCache()
);
$reflClass = new ReflectionClass("\Controller\\" . $reportableClass);
$annotation = $annotationReader->getClassAnnotation(
$reflClass, 'Custom_Annotation'
);
if (is_null($annotation)) {
unset($classes[$key]);
}
}
$output->writeln($path);
}
我发现这个SOF代码,但我不知道如何搜索所有控制器类和内他们所有的动作..
对不起,但我可以问你如何使用这个函数来获取“操作”有注释@Module?例如:indexAction等... –
你可以在你的控制器中添加这个,不要忘记“使用”,然后用你的@module的命名空间替换这个“Acme \ YourBundle \ Module”,最后在你的indexAction中你可以调用这个函数$这个 - > getControllersWithAnnotationModules() –