2014-03-25 26 views
0

在我的web應用程序中,我有一個名爲producer offer的表,我需要再添加兩列,它顯示添加的列但不保存輸入的值 。但是,當我查看這個值時,它顯示爲「未設置」在視圖中。我應該如何解決這個問題?Yii沒有在表中保存新添加的列

public function rules() 
    { 

     return array(
      array(' vegetable_id, offered_qty, unit_cost, unit_delivery_cost', 'required'), 
      array(' offered_qty, unit_cost, unit_delivery_cost, booking_status, booked_by, available_days', 'numerical', 'integerOnly'=>true), 
      array('user_id', 'length', 'max'=>11), 
      // The following rule is used by search(). 
      // Please remove those attributes that should not be searched. 
      array('id,userName,user_id, vegetable_id, offered_qty, unit_cost, unit_delivery_cost, offered_date, booking_status, booked_by, available_days', 'safe', 'on'=>'search'), 
      //array('booked_qty','on'=>'update') 
      array('booked_qty,available_qty','numerical', 'safe'=>true), 
     ); 
    } 
public function attributeLabels() 
    { 
     return array(
      'producerOfferUserRelation.name' => 'Offered By', 
      'producerOfferVegetableRelation.name' => 'Offered Vegetable', 
      'offered_qty' => 'Offered Qty(/KG)', 
      'unit_cost' => 'Unit Cost(RS/KG)', 
      'unit_delivery_cost' => 'Unit Delivery Cost(RS/KM)', 
      'offered_date' => 'Offered Date', 
      'booking_status' => 'Booking Status', 
      'booked_by' => 'Booked By', 
      'available_days' => 'Available Days', 
      'booked_qty'=>'Booked quantity', 
      'available_qty'=>'Available quantity' 
     ); 
    } 

我的代碼ProducerOfferController.php

public function actionUpdate($id) 
    { 
     $model=$this->loadModel($id); 
     $booked_qty=$model->booked_qty; 
    if(isset($_POST['ProducerOffer'])) 
    { 
     $model->booked_qty=$_POST['ProducerOffer']['booked_qty']; 

     $model->available_qty=$model->offered_qty-$model->booked_qty; 

     $model->attributes=$_POST['ProducerOffer']; 
     $model->save(); 
     if ($model->hasErrors() === false) 
     { 
      $this->redirect(Yii::app()->user->returnUrl); 
     } 
    } 
    else 
    { 
     Yii::app()->user->setReturnUrl($_GET['returnUrl']); 
    } 
    $this->render('form',array('model'=>$model,)); 
} 
+0

你確定他們是在您的文章中實際設置? (你是否嘗試過var_dump或其他?)。 – Blizz

回答

0

變化

$model->booked_qty=$_POST['ProducerOffer']['booked_qty']; 
    $model->available_qty=$model->offered_qty-$model->booked_qty; 
    $model->attributes=$_POST['ProducerOffer']; 

$model->attributes=$_POST['ProducerOffer']; 
    $model->booked_qty=$_POST['ProducerOffer']['booked_qty']; 
    $model->available_qty=$model->offered_qty-$model->booked_qty; 
+0

試過,即使那時它的不顯示結果也是一樣的。 – user2492854

相關問題