Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get configuration params in Controller Console in Yii2 Framework

Tags:

yii2

How to get configuration params in Console Controller in Yii2 Framework

I try below code but its not working

Yii::$app->params['params_1']
like image 954
kang dadang Avatar asked Jul 21 '16 08:07

kang dadang


2 Answers

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']; 
like image 144
Yasin Patel Avatar answered Sep 22 '22 10:09

Yasin Patel


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'];?>
like image 44
Nana Partykar Avatar answered Sep 23 '22 10:09

Nana Partykar