强制包含 Yii 框架中文件夹中的所有类
我可以通过以下方式强制包含一个模型:
Yii::import("application.models.modelName", true);
我应该怎么做才能包含模型目录中的所有模型?
这是我尝试过的:
Yii::import("application.models.*", true);
它不起作用,因为 Yii 仅在需要使用时才会导入。
I can force include one model by:
Yii::import("application.models.modelName", true);
What should I do to include all models from the models directory?
Here's what I've tried:
Yii::import("application.models.*", true);
It doesn't work because Yii will import only when there is a need to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
真的,除了使用它们之外,为什么还要导入它呢?
自动加载 php 功能是无价的:)
Really, why would you want to import it except to use them?
Autoloading php feature is priceless :)
易伊做不到这一点。与真正的包含相比,导入是相当轻量级的,但如果您必须完成这一点,这里有一个片段:
我不怀疑在某些情况下这种方法是最好的,但您确实必须确保它在您的场景中。
Yii can't do that. Importing is pretty lightweight compared to real inclusion, but if you must accomplish that, here's a snippet:
I don't doubt there are cases when this approach is the best, but you really have to make sure it is in your scenario.