获取 Yii 中的所有模型名称 [英] Get all of model names in Yii

查看:33
本文介绍了获取 Yii 中的所有模型名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的 Web 应用程序创建一个模块.我正在使用 Yii 1.1.14.如何检索所有模型名称?

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.

推荐答案

我不确定我对您问题的理解是否正确.如果您必须检索所有模型的名称,那么您解决手头问题的方法可能不是最佳的?无论如何,这就是我要解决的问题:

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/>";
}

这将遍历模块中模型子文件夹中的所有文件,并在删除.php"部分后显示它们.如果要访问整个项目更改的所有模型

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')

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

这篇关于获取 Yii 中的所有模型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆