我使用Yii2
先進的模板, 我想訪問params.php
在main-local.php
文件, 我稱這種方式:Yii2 PARAMS內本地配置文件訪問的公共目錄
主local.php:
'mailer' => [
'class' => 'myClass',
'apikey' => \Yii::$app->params['mandrill_api_key'],
'viewPath' => '@common/mail',
],
,我已經存儲在此mandrill_api_key
在params.php
params.php:
<?php
return [
'adminEmail' => '[email protected]',
'supportEmail' => '[email protected]',
'user.passwordResetTokenExpire' => 3600,
'mandrill_api_key' => 'mykey'
];
我得到這個錯誤:
Notice: Trying to get property of non-object in C:\xampp\htdocs\myproject\common\config\main-local.php on line 25
我應該怎麼做才能訪問這些參數?
- A user makes a request to the entry script web/index.php.
- The entry script loads the application configuration and creates an application instance to handle the request.
- The application resolves the requested route with the help of the request application component.
- ...
這樣\Yii::$app
尚不存在因此錯誤:
您是否嘗試添加\,所以如此mething like:\ Yii :: $ app-> params ['mandrill_api_key'] – Criesto
是的,我已經嘗試過,但沒有工作,可能是我需要定義應用程序引導時的東西。 –