class siteSetting extends Component
{
public $setting = [];
public function init()
{
parent::init();
$this->setting = Setting::find()->asArray()->all();
}
public function get($param)
{
$search = array_search($param, array_column($this->setting, 'params'));
if ($search !== false) {
return $this->setting[$search]['value'];
} else {
return 'unknown setting param';
}
}
}
'on afterAction' => function ($event) {
if (Yii::$app->siteSetting->get('siteActive') == 'off') {
return Yii::$app->response->redirect(['site/offline']);
} else {
return false;
}
},
class ApiController extends Controller
{
public $token;
public $layout = 'blank';
// public function beforeAction($action)
// {
// $this->token = Yii::$app->params['token'];
// return parent::beforeAction($action);
// }
public function __constructor()
{
self::$token = Yii::$app->params['token'];
}
public function actionIndex()
{
var_dump($this->token); // NULL
}
public function beforeAction($action)
{
$this->token = Yii::$app->params['token'];
return parent::beforeAction($action);
}