$form = $this->beginWidget('CActiveForm', array('id' => 'sanpham-form', 'enableAjaxValidation' => false)); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <div class="form-group"> <?php echo $form->labelEx($model, 'loaisanpham_id'); ?> <?php echo $form->dropDownList($model, 'loaisanpham_id', Loaisanpham::model()->getLoaisanphamsName()); ?> <?php echo $form->error($model, 'loaisanpham_id'); ?> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'ten'); ?> <?php echo $form->textField($model, 'ten', array('size' => 30, 'maxlength' => 30, 'class' => 'form-control')); ?> <?php echo $form->error($model, 'ten');
/** * 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 $id the ID of the model to be loaded * @return Loaisanpham the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Loaisanpham::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function getLoaisanphamName() { $loaisanpham = Loaisanpham::model()->findByPk($this->loaisanpham_id); if ($loaisanpham) { return $loaisanpham->ten; } else { return 'Chưa Xác Định'; } }