我是新手。我想在yii中创建更新表单。我创建了一个控制器Adminprofile并调用模型ProfileForm。在我的视图中' adminprofile.php'我想从表格中加载管理员的价值' superadmin'在名称和密码字段中。现在它仅显示没有值的字段。
我想将更新用作$update=update superadmin set username='$username',password='$password' where id='1'
SiteController.php
public function actionAdminprofile()
{
$model=new ProfileForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$password='=?UTF-8?B?'.base64_encode($model->password).'?=';
$this->refresh();
}
}
$this->render('adminprofile',array('model'=>$model));
}
ProfileForm.php (MODEL)
class ProfileForm extends CFormModel
{
public $name;
public $password;
public function rules()
{
return array(
// name, email, subject and body are required
array('name, password', 'required'),
);
}
}
Adminprofile.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'contact-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->textField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<?php endif; ?>