我需要从 Yii 2 中的前端控制器访问后端模型

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

我正在使用 Yii 2 框架。如何从我的前端控制器访问我的后端模型。我尝试了下面的代码。

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

但是我遇到了这个错误

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

由于后端的命名空间是 backend,您应该简单地尝试:

$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.

阅读更多:http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html