PHP code example of yii1tech / config
1. Go to this page and download the library: Download yii1tech/config library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yii1tech / config example snippets
[
'behaviors' => [
'configFromManagerBehavior' => [
'class' => yii1tech\config\ConfiguresAppFromConfigManager::class,
],
// ...
],
'components' => [
'configManager' => [
'class' => yii1tech\config\Manager::class,
'items' => [
'appName' => [
'path' => 'name',
'label' => 'Application Name',
'rules' => [
['
$configManager = Yii::app()->get('configManager');
$configManager->configure(Yii::app());
return [
'appName' => [
'path' => 'name',
'label' => 'Application Name',
'rules' => [
[' 'label' => 'Date representation format',
'rules' => [
['adminTheme' => [
'label' => 'Admin interface theme',
'path' => ['modules', 'admin', 'theme'],
'rules' => [
['
namespace app\controllers;
use CController;
use CHtml;
use Yii;
class ConfigController extends CController
{
/**
* Performs batch updated of application configuration records.
*/
public function actionIndex()
{
/* @var $configManager \yii1tech\config\Manager */
$configManager = Yii::app()->get('configManager');
$configManager->restore();
$models = $configManager->getItems();
if (!empty($_POST)) {
$valid = true;
foreach ($models as $model) {
$modelName = CHtml::modelName($model);
if (isset($_POST[$modelName][$model->id])) {
$model->setAttributes($_POST[$modelName][$model->id]);
}
$valid = $valid && $model->validate();
}
if ($valid) {
$configManager->save();
Yii::app()->getComponent('user')->setFlash('success', 'Configuration saved.');
$controller->refresh();
return;
}
}
return $this->render('index', [
'models' => $models,
]);
}
/**
* Restores default values for the application configuration.
*/
public function actionDefault()
{
/* @var $configManager \yii1tech\config\Manager */
$configManager = Yii::$app->get('configManager');
$configManager->reset();
Yii::app()->getComponent('user')->setFlash('success', 'Default configuration restored.');
$this->redirect(['index']);
return;
}
}
/** @var $this CController */
/** @var $form CActiveForm */