How can I connect a radio button to a controller?

This is probably a basic question and something fairly easy to many people.

How can I connect for example a switch/radio button to change a value in my config.

For example I need to be able to toggle a maintenance page on and off I found this stackoverflow which basically says use the below code to change the value but I am struggling how to connect a switch radio button or something to it


Yii::$app->maintenanceMode->enable=FALSE;

If you do that, then maintenance mode will be on for just that request. If you want it on permanently (until someone flips the switch again) then that’s a more complex issue.

For the first situation (where you turn on maintenance mode for the current request) you just need to send a request to a controller action either via a form submit or AJAX and on the action side check the current state of the check-box (e.g. is it checked?) if yes [color=#660066][size=2]Yii[/size][/color][color=#666600][size=2]::[/size][/color][size=2]$app[/size][color=#666600][size=2]->[/size][/color][size=2]maintenanceMode[/size][color=#666600][size=2]->[/size][/color][size=2]enable to true, if not checked the set it to false.[/size]

[size=2]See this link for creating form: http://www.yiiframework.com/doc-2.0/guide-input-forms.html[/size]

[size=2]

[/size]

[size=2]For the second situation you need to manipulate the config file and for this you need yii’s advanced application or a similar setup, in which a backend application switches the frontend application into maintenance mode.[/size]

[size=2]To do this, you have to have a form or ajax that send the current state of the check-box to a backed controller action. From there you include the frontend config file into a variable, activate or deactivate maintenance mode and then write using http://php.net/manual/en/function.var-export.php to the config file.[/size]

[size=2]

[/size]

[size=2]If you don’t have to advanced application, then you have to put a condition to not block admin’s out of the application if it’s in maintenance mode.[/size]

[size=2]

[/size]

[size=2]There are other tricks also, for example in the main config you can include a script for the maintenance mode value that dynamically return true or false based on cookies or IP etc.[/size]

[size=2]

[/size]