Thanks! I’ll give it a try. I just realized something, the models directory is being pre-loaded by default in Yii. Which is what you meant by turning autoload to false.
Apparently the model I used to test was already used somewhere else on the website. yii::import() will also not work; all the models are already on the import list.
I just need the Yii autoload feature to throw an exception if I try to load in a model that does not exist; instead of throwing a PHP error about failing to include a file. I cannot handle the PHP error, but I can handle the exception.
If you want to make a feature request… you can do it… but at least you need to specify a good reason as why to add this feature… because if it’s something that only you need and only for one project… there is no point in adding this to the framework… so when you make the feature request think about this and give some good reasons
As for your problem… if I got it right… you don’t need to check if the class exist - as this means that the class is loaded… (this is what clas_exists() checks)
you need to know if the file exists… so that it can be included for the first time…
Problem is that there is no way to make a fast solution for this as the class can be in any folder or subfolder… so all folders would need to be checked…
Maybe you can get a compromise… like keeping all those classes in one folder… then you can just test with file_exist() to see if there is a file with the class name… as in Yii one class is one file with the same name…
I wanted to suggest to try to do the file_includes just like it’s doing right now. If all of them fail; throw an exception.
I havent looked at the code yet, but my guesstimate is that it should be quite easy to implement. I’ll have another look at this in a few days. Thanks for your feedback mdomba!
I have the project with many subprojects. Subprojects use common models, which i store my system.common.models directory. One common model have many children from subproject’s models, when I inizialize from subproject my common model I want check what models I have in children by class_exists function, and I need use autoload.
But I got error failed to open strem: No such file or directory, if I try check not exists children className.
Well, check_class will be check out of class exists, but generate error. It’s not logical.
I found solution for my needs: instead of class_exists I use
I know this post is outdated, but I was stuck on this and as it turns out the solution as of PHP 5.3.2 is pretty straightforward, posting here just for reference
That’s only suitable if all your classes are located in a predetermined location - application.models, in your example. If you use modules then this is not good.