Home  >  Article  >  Backend Development  >  Yii custom model path_PHP tutorial

Yii custom model path_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:20834browse

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/777155.htmlTechArticleFor example, there are two Yii projects, namely test1 and test2. In test1, there is already a model. Test2 directly calls the model in test1. In fact, add an alias and then modify the configuration...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn