Yii Metadata component helps to get information about models,controllers and actions from your application
1. Place Metadata.php to directory with components of your application (your_app_dir/protected/components/) or to extensions (your_app_dir/protected/extensions/)
2. Add 'metadata' element to 'components' in your application config (your_app_dir/protected/config/main.php):
... 'components'=>array( 'metadata'=>array('class'=>'Metadata'), ... ),
If you place Metadata.php to extensions, then you should write 'class'=>'ext.Metadata' instead of 'class'=>'Metadata'
3. Use:
$user_actions = Yii::app()->metadata->getActions('UserController'); var_dump($user_actions); #Get actions of 'UserController' $controllers = Yii::app()->metadata->getControllers(); #You can specify module name as parameter var_dump($controllers); #Get list of application controllers $controllersWithActions = Yii::app()->metadata->getControllersActions('user'); #if no $module param, controllers&actions of application will returned var_dump($controllers); #Get controllers and their actions of module 'user' $models = Yii::app()->metadata->getModels(); #You can specify module name as parameter var_dump($models); #Get list of models application $modules = Yii::app()->metadata->getModules(); var_dump($modules);
v0.2:
If some modules in your app have controllers with same names, MetaData will raise fatal error, when you will try to get information about controllers of both this modules.
getModules method can not find modules inside other modules. (will fixed in next ver.)
MetaData cannot find information about controller actions, specified by actions() method (will fixed in next ver.)
November 04, 2010 v0.2 released (fixed some bugs)
June 13, 2010 Initial release.
Total 4 comments
I think that class should have name EMetadata
great job! useful for auth system , auto list all available actions , controllers ,modules , and then assign it to some role ,you don't need input it manually anymore and can choice it from a tree list view under this extension helping .:)
and............ any one test it on nested modules circumstance? the nest version should support the nested module situation . i roughly read the code and found that it doesn't support nested modules .
Very nice extension and smart code! Thanks.
For example you can use it in your Yii based CMS to get list of available modules/controllers/actions and actions dinamically. p.s.: Sorry for my english, it isn't good. Usually i speak russian. Correct me please if you see stange text in documentation :)
Leave a comment
Please login to leave your comment.