Yii import conditions

2019-09-17 14:52发布

models. * 
classes. * 

How do not import some files of the directories? And import them only when we need?

For example: I need import file models/SomeModel.php only in controller SomeController.php. I need import file classes/SomeClass.php only in controller SomeController.php and Some2Controller.php.

标签: yii
1条回答
放我归山
2楼-- · 2019-09-17 15:37

use when needed:

Yii::import('application.models.SomeModel');// protected/models/SomeModel.php
Yii::import('application.classes.SomeClass');//  protected/classes/SomeClass.php

But beware that import() is different than require or include, import relies on Class names being the same as file names.

查看更多
登录 后发表回答