How to get configuration params
in Console Controller in Yii2 Framework
I try below code but its not working
Yii::$app->params['params_1']
Try This:
Code in config/params.php
<?php
return array(
'apptitle' => 'stackOverlfow',
//Define PARAMS as you need.
);
?>
You can use PARAM as below:
\Yii::$app->params['apptitle'];
Example:
echo "App title is:". \Yii::$app->params['apptitle'];
As you mentioned Basic Template Of Yii.
config/web.php
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
.
.
.
],
'params' => $params,
];
return $config;
?>
config/params.php
<?php
$params = [
'params_1' => 'YourValue'
];
return $params;
?>
SomeWhere.php
<?=Yii::$app->params['params_1'];?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With