Question

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.

Was it helpful?

Solution

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')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top