如何在 symfony 中获取模块列表
我是 symfony 的新手,我正在学习它。我想动态获取所有工作模块及其方法来构建一个列表来实现 ACL。
foreach(getModules() as $module)
{
echo $moudule .' has following methods: ';
foreach( $module as $method )
{
echo $method.'<br />';
}
}
以上代码不是有效代码。这只是一个获得东西的想法。
I am new to symfony and I am learning it. I want to get all working modules and their methods dynamically to bulild a list to implement ACL.
foreach(getModules() as $module)
{
echo $moudule .' has following methods: ';
foreach( $module as $method )
{
echo $method.'<br />';
}
}
Above code is not a valid code. it is just an idea to get things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Symfony 1 并不(据我所知)在运行时维护所有模块的列表。出于性能原因,它仅在调用时尝试加载一个。您可以尝试一些肮脏的事情,例如解析自动加载器缓存,但我不推荐它。
我假设您需要该列表,以便可以为 ACL 工具构建管理 UI。另一种方法是检索路由列表,这绝对是可能的,例如 sfContext::getInstance()->getRouting()->getRoutes()。
如果您希望 ACL 应用于特定的类或对象,而不是 URL 或操作,那么我建议转到 Symfony2内置此功能。
Symfony 1 doesn't (as far as I can find) maintain a list of all modules during runtime. For performance reasons, it only tries to load one when it's called. You could try something dirty like parsing the autoloader cache, but I wouldn't recommend it.
I assume you want the list so that you can build an admin UI for your ACL tool. The alternative approach is to retrieve a list of routes, which is definitely possible, e.g.
sfContext::getInstance()->getRouting()->getRoutes()
.If you want your ACLs to apply to specific classes or objects, rather than URLs or actions, then I suggest moving to Symfony2 which has this functionality built in.
您可以使用本机代码索引应用程序的所有模块。
您可以使用操作或组件来执行此操作。
这是代码:
... 和模板:
现在,您有了所有模块的列表。
You can index all the modules of your application using native code.
You can use an action or a component to do this.
Here's the code:
... and the template:
Now, you have a list of all your modules.