/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = SubjectName::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Subjects'])) { $model->attributes = $_POST['Subjects']; $data = SubjectName::model()->findByAttributes(array('id' => $model->name)); if ($data != NULL) { $model->name = $data->name; $model->code = $data->code; } if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } Yii::app()->clientScript->scriptMap['jquery.js'] = false; $this->renderPartial('update', array('model' => $model, 'id' => 1, 'batch_id' => $_GET['val1']), false, true); }
<?php $form = $this->beginWidget('CActiveForm', array('id' => 'subjects-form', 'enableAjaxValidation' => true)); $model; ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php $data = CHtml::listData(SubjectName::model()->findAll(), 'id', 'name'); ?> <?php echo $form->errorSummary($model); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?php echo $form->labelEx($model, Yii::t('subjects', 'name')); ?> </td> <td><?php echo $form->dropDownList($model, 'name', $data, array('prompt' => 'Select')); ?> <?php echo $form->error($model, 'name'); ?> </td> </tr> <tr> <td><?php echo $form->labelEx($model, Yii::t('subjects', 'max_weekly_classes'));