我是Yii Framework的初學者。我創建了帶有Yii小部件的_form.php CActiveForm.I已經制作了複選框列表for days days.I已經在actioncreate上的序列化複選框值並保存到數據庫表。其實問題是,當我調用actionupdate然後我的檢查值沒有顯示我已經插入actioncreate.actioncreate和actionupdate使用相同的形式_form.php。如何在Yii 1.6中選中checkboxlist?
我寫我的代碼如下
actioncreate
公共職能actionCreate(){ $ 模型=新CustomerAccounts;
if(isset($_POST['CustomerAccounts'])) { $model->attributes=$_POST['CustomerAccounts']; $model->DateCreated = date('Y-m-d H:i:s'); $model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']); if($model->save()) { Yii::app()->user->setFlash('success', 'Customer Account create successfully.'); $this->redirect(array('admin')); } else { Yii::app()->user->setFlash('danger','An error occurred. Please try again.'); } } $this->render('create',array( 'model'=>$model, ));
}
actionupdate
公共函數actionUpdate($ ID) { $模型= $這 - > loadModel($ ID);
if(isset($_POST['CustomerAccounts'])) { $model->attributes=$_POST['CustomerAccounts']; $model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']); $model->DateCreated = date('Y-m-d H:i:s'); if($model->save()) { Yii::app()->user->setFlash('success', 'Customer Account update successfully.'); $this->redirect(array('admin')); } else { Yii::app()->user->setFlash('danger','An error occurred. Please try again.'); } } $this->render('update',array( 'model'=>$model, ));
}
_form.php這個
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'customer-accounts-form',
'enableAjaxValidation'=>false,
<div class="row">
<div class="col-lg-12" style="padding-left: 34px;">
<?php echo $form->labelEx($model, 'DeliveryDay'); ?>
<?php echo $form->error($model, 'DeliveryDay'); ?>
<div id="checkbox" style="padding-left: 90px;">
<?php
$htmlOptions = array('template' => '<tr><td >{input}</td> <td> {label}</td> </tr', 'multiple' => true, 'checked' => 'checked');
echo $form->checkBoxList($model, 'DeliveryDay', Yii::app()->params['WeekDays'], $htmlOptions);
?>
</div></div></div>
<?php $this->endWidget(); ?>
這裏我的模型
類CustomerAccounts擴展的CActiveRecord {
public function tableName()
{
return 'customer_accounts';
}
public function rules()
{
return array(
array('DeliveryDay, Status, CustomerID, Employee_ID, PaymentModeID', 'required'),
array('CustomerID, Employee_ID, PaymentModeID, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, Status', 'numerical', 'integerOnly'=>true),
array('DateJoin', 'length', 'max'=>250),
array('Description', 'safe'),
array('CustomerAccountID, CustomerID, Employee_ID, PaymentModeID, DateJoin, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, DeliveryDay, Description, Status, DateCreated', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'customer' => array(self::BELONGS_TO, 'Customer', 'CustomerID'),
'employee' => array(self::BELONGS_TO, 'Employee', 'Employee_ID'),
'paymentMode' => array(self::BELONGS_TO, 'PaymentMods', 'PaymentModeID'),
);
}
public function attributeLabels()
{
return array(
'CustomerAccountID' => 'Customer Account',
'CustomerID' => 'Customer',
//'Employee_ID' => 'Employee',
'Employee_ID' => 'Sale Person',
'PaymentModeID' => 'Payment Mode',
'DateJoin' => 'Date Join',
'PcBottle' => 'Pc Bottle',
'Bottle6Ltr' => 'Bottle6 Ltr',
'Bottle1500Ml' => 'Bottle1500 Ml',
'Bottle500Ml' => 'Bottle500 Ml',
'TabStand' => 'Tab Stand',
'Pump' => 'Pump',
'DispensirStatus' => 'Dispensir Status',
'PCBottlesQuantity' => 'Pcbottles Quantity',
'PCBottleSecurity' => 'Pcbottle Security',
'DispensirQuantity' => 'Dispensir Quantity',
'DispensirSerialNo' => 'Dispensir Serial No',
'DispensirSecurity' => 'Dispensir Security',
'TotalAmount' => 'Total Amount',
'DeliveryDay' => 'Delivery Day',
'Description' => 'Description',
'Status' => 'Status',
'DateCreated' => 'Date Created',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('CustomerAccountID',$this->CustomerAccountID);
$criteria->compare('CustomerID',$this->CustomerID);
$criteria->compare('Employee_ID',$this->Employee_ID);
$criteria->compare('PaymentModeID',$this->PaymentModeID);
$criteria->compare('DateJoin',$this->DateJoin,true);
$criteria->compare('PcBottle',$this->PcBottle);
$criteria->compare('Bottle6Ltr',$this->Bottle6Ltr);
$criteria->compare('Bottle1500Ml',$this->Bottle1500Ml);
$criteria->compare('Bottle500Ml',$this->Bottle500Ml);
$criteria->compare('TabStand',$this->TabStand);
$criteria->compare('Pump',$this->Pump);
$criteria->compare('DispensirStatus',$this->DispensirStatus);
$criteria->compare('PCBottlesQuantity',$this->PCBottlesQuantity);
$criteria->compare('PCBottleSecurity',$this->PCBottleSecurity);
$criteria->compare('DispensirQuantity',$this->DispensirQuantity);
$criteria->compare('DispensirSerialNo',$this->DispensirSerialNo);
$criteria->compare('DispensirSecurity',$this->DispensirSecurity);
$criteria->compare('TotalAmount',$this->TotalAmount);
$criteria->compare('DeliveryDay',$this->DeliveryDay,true);
$criteria->compare('Description',$this->Description,true);
$criteria->compare('Status',$this->Status);
$criteria->compare('DateCreated',$this->DateCreated,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
請問誰能告訴我,當我打電話actionupdate如何檢查的值將會從數據庫表顯示?
你反序列化值之前顯示編輯表單?展示你的模型。 – SiZE
我有更新模型在我的問題。我沒有未顯示的值之前顯示編輯窗體。請你告訴我如何我可以顯示編輯窗體上的值? –
例如,進入'afterFind':'public function afterFind(){parent :: afterFind(); $ this-> DeliveryDay = unserialize($ this-> DeliveryDay); }' – SiZE