Home >Backend Development >PHP Tutorial >Yii custom model path_PHP tutorial
For example, there are two Yii projects, test1 and test2.
In test1, there is already a model. Test2 directly calls the model in test1. In fact, just add an alias and then modify the configuration.
First add in the index.php entry file require_once($yii); followed by:
Yii::setPathOfAlias(<span>'pubModels'</span>, <span>dirname</span>(<span>__FILE__</span>) . <span>'/../test1/protected/models'</span>);
Just set your project path according to the actual situation.
Then open the configuration file main.php and add
in import<span>'import'</span>=><span>array</span><span>( </span><span>'application.models.*'</span>, <span>'pubModels.*'</span>, <span>//</span><span> 这个就是 test1 的模型</span> <span>'application.components.*'</span>,<span> )</span>
If you don’t need the model of the current project, just comment out 'application.models.*'.
This way you can share a model.
If you use giix, you can also use this method to call the same one. Extensions, language packs, etc. can set aliases and then share the call.