Deny access to controller if component->value is zero or not


(Pellicanipasquale) #1

Hi all, how can manage this case in controller behaviors structure ? I’ve this code in controller:
public function behaviors()
{
return [
‘access’ => [
‘class’ => AccessControl::className(),
‘rules’ => [
[
‘allow’ => true,
‘roles’ => [’@’], // you can use matchCallback to create more powerful check
],
‘allow’ => false,
‘denyCallback’ => function ($rule, $action) { //PHP callable that should be called when this rule will deny the access.
$settings = Yii::$app->settings;
$value = $settings->get(‘ConfigurationForm’, ‘qualifica_enabled’);
//Write your logic here to deny the action
if($value == 0){
throw new \Exception(‘You are not allowed to access this page’);
}
}
],
],
‘verbs’ => [
‘class’ => VerbFilter::className(),
‘actions’ => [
‘delete’ => [‘POST’],
],
],
];
}