简体   繁体   中英

I need to access backend models from a frontend controller in Yii 2

I am using Yii 2 framework. How can I access my backend models from my frontend controller. I tried the code below.

$tnc = new \app\models\PaymentsMethod\TermsAndConditions();

But I got this error

Class 'app\models\PaymentsMethod\TermsAndConditions' not found

Since namespace for backend is backend , you should simply try :

$tnc = \backend\models\PaymentsMethod\TermsAndConditions();

In the Advanced Application Template, each tier has its own root alias. For example, the front-end tier has a root alias @frontend , while the back-end tier root alias is @backend . As a result, you may put the front-end classes under the namespace frontend while the back-end classes are under backend . This will allow these classes to be autoloaded by the Yii autoloader.

Read more : http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM