请确保您具有正确的配置/主.php(这是使用高级模板的后端应用程序的示例)
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'your-app-backend',
'name' => 'Your APP Backend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'backend\controllers',
'modules' => [],
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
],
'params' => $params,
];
假设你有一个参数.php
<?php
return [
'adminEmail' => 'my_mail@example.com',
];
你可以使用 yii::$app->params 获取参数
Yii::$app->params['adminEmail'];
用于打印
echo Yii::$app->params['adminEmail'];