Get all of model names in Yii

孤街浪徒 提交于 2019-12-13 04:33:27

问题


I am creating a module for our web application. I am using Yii 1.1.14. How do I retrieve all of the model names?

I tried this but still I got no luck.


回答1:


I am not sure if my understanding of your question is correct. If you have to retrieve the name of all your models, then maybe your approach to the problem at hand is not optimal? Anyway here is what i would approach the problem:

foreach(glob('./protected/modules/<module-name>/models/*.php') as $filename){
    echo str_replace(".php", "", $filename)."<br/>";
}

This iterates through all files in your models sub-folder within your module and displays them after removing the ".php" part. If you want to access all models for the entire project change

glob('./protected/modules/<module-name>/models/*.php')

to

glob('./protected/models/*.php')


来源:https://stackoverflow.com/questions/18247862/get-all-of-model-names-in-yii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!