[英]I need to access backend models from a frontend controller in Yii 2
I am using Yii 2 framework. 我正在使用Yii 2框架。 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 : 由于后端的命名空间是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
. 例如,前端层具有根别名@frontend
,而后端层根别名为@backend
。 As a result, you may put the front-end classes under the namespacefrontend
while the back-end classes are underbackend
. 因此,您可以将前端类放在命名空间frontend
下,而后端类位于backend
。 This will allow these classes to be autoloaded by the Yii autoloader. 这将允许这些类由Yii自动加载器自动加载。
Read more : http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html 阅读更多: http : //www.yiiframework.com/doc-2.0/guide-concept-autoloading.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.