How to get Modules list in symfony
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 ju开发者_如何学Cst an idea to get things.
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:
$this->modulos = array();
$aplicacion = "admin"; //The name of your symfony app
$directorio = opendir("../apps/$aplicacion/modules");
while($file = readdir($directorio)){
if($file=="..")continue;
if($file==".")continue;
// here you can filter the modules
$this->modulos[] = $file;
}
... and the template:
<?php foreach($modulos as $modulo):?>
<div>
<?php echo link_to($modulo,"@default?module=$modulo&action=index") ?>
</div>
<?php endforeach; ?>
Now, you have a list of all your modules.
精彩评论