I am new to the Yii framework. I created a table TblUser. Now I have three columns username, passwordand email. I use operations CRUDin Yii. The connection to the database was successful. I also managed to create a new record in the table. Now the database entry reads as
+----+----------+----------+--------------------+
| id | username | password | email |
+----+----------+----------+--------------------+
| 1 | test1 | pass1 | test1@example.com |
| 2 | test2 | pass2 | test2@example.com |
| 3 | test3 | pass3 | test3@example.com |
+-----------------------------------------------+
Now in the presentation form, I deleted the field emailby commenting (_form.php). I use this form to update the remaining fields.
<?php
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'tbl-user-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
To use the rest of the fields, I commented out the field emailin _form.php. Now in my controller I have an update code as shown below:
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if(isset($_POST['TblUser']))
{
$model->attributes=$_POST['TblUser'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
}
When I see request logs, updated request
UPDATE `tbl_user` SET `id`=2, `username`='1234', `password`='1234', `email`='test2@example.com' WHERE `tbl_user`.`id`=2
but not
UPDATE `tbl_user` SET `password`='1234' WHERE `tbl_user`.`id`=2
, , , . . .