简体   繁体   English

CakePHP(v1.1)-如何检索模型列表?

[英]CakePHP (v1.1) - How do I retrieve a list of the models?

Does anyone know if there's a simple way to retrieve the list of models in cakePHP v1.1? 有谁知道在cakePHP v1.1中是否有一种简单的方法来检索模型列表? For example, if the app has models Student, Teacher, and Grade, I'm looking for a way to get an array of these models. 例如,如果应用程序具有学生模型,教师模型和年级模型,我正在寻找一种获取这些模型阵列的方法。 Any suggestions? 有什么建议么? Thank you much. 非常感谢

You can try this in the controller: 您可以在控制器中尝试以下操作:

// Teachercontroller for example
$this->Teacher->hasMany;

this gives back all the related Models. 这将返回所有相关的模型。 Same with belongsTo etc. belongsTo等相同

It looks like the best way to do this is to simply check which files exist in the models directory and check if they contain a class. 看起来最好的方法是简单地检查models目录中存在哪些文件,并检查它们是否包含类。 I've decided that this is the best method based on the fact that this is essentially what the loadModel() function does itself. 基于以下事实,我决定这是最好的方法,即这实际上就是loadModel()函数本身所做的事情。 The code for the loadModel() function can be found here . loadModel()函数的代码可以在此处找到。 The program I ended up not needing to get the list of all models, but hopefully this answer can steer people in the right direction if anyone does need such a list. 我最终编写的程序不需要获取所有型号的列表,但是希望这个答案可以引导人们朝着正确的方向发展,如果有人确实需要这样的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM