一.原出处:
二具体:
1.创建model create protected/backend/models/ConfigForm.php
2.创建controller protected/backend/controllers/ConfigController.php
setAttributes($arr); if (isset($_POST['ConfigForm'])) { $config = array( 'adminEmail'=>$_POST['ConfigForm']['adminEmail'], 'paramName'=>$_POST['ConfigForm']['paramName'], ); $str = base64_encode(serialize($config)); file_put_contents($file, $str); Yii::app()->user->setFlash('config', Yii::t('app', 'Your new options have been saved.')); $model->setAttributes($config); } $this->render('index',array('model'=>$model)); }}?>
3.创建view protected/backend/views/config/index.php
beginWidget('CActiveForm', array( 'id' => 'config-form', 'enableAjaxValidation' => false,));?>user->hasFlash('config')):?>
user->getFlash('config'); ?>* . errorSummary($model); ?>
labelEx($model,'adminEmail'); ?> textField($model, 'adminEmail'); ?> error($model,'adminEmail'); ?>labelEx($model,'paramName'); ?> textField($model, 'paramName'); ?> error($model,'paramName'); ?>endWidget(); ?>
4.创建两个文件
create the following config files under protected/config
:
- params.inc
- params.php
5.编辑 protected/config/main.php
// application-level parameters that can be accessed// using Yii::app()->params['paramName']'params'=>require(dirname(__FILE__).'/params.php'),
6.编辑 protected/config/params.php
'P@bl0', 'someOption'=>true, ) );?>