2016-10-21 81 views
0

我在表中添加了一個新列'delivery_state'如何將新屬性添加到模型yii框架?

並在yii框架中使用它。

我已經在我已經在功能的規則和屬性都加這個「delivery_state」,但我有沒有定義錯誤消息財產delivery_state以下功能

public function rules() 
    { 
     // NOTE: you should only define rules for those attributes that 
     // will receive user inputs. 
     return array(
      array('buyer_id, seller_id, lta_product_id, currency_id, order_date, delivery_date, payment_date', 'required'), 
      array('seller_id, currency_id', 'numerical', 'integerOnly'=>true), 
      array('buyer_id, lta_product_id, quantity', 'length', 'max'=>11), 
      array('unitary_price, total_price', 'length', 'max'=>10), 
      array('delivery_title, delivery_address,delivery_state, delivery_city, delivery_country_id', 'length', 'max'=>255), 
      array('delivery_zip', 'length', 'max'=>16), 
      array('phone_number', 'length', 'max'=>24), 
      array('notes', 'length', 'max'=>1024), 
      array('status', 'length', 'max'=>1), 
      // The following rule is used by search(). 
      // Please remove those attributes that should not be searched. 
      array('id, buyer_id, seller_id, lta_product_id, quantity, unitary_price, total_price, currency_id, order_date, delivery_date, payment_date, delivery_title, delivery_address,delivery_city, delivery_zip, delivery_country_id, phone_number, notes, status', 'safe', 'on'=>'search'), 
     ); 
    } 
public function attributeLabels() 
    { 
     return array(
      'id' => 'Id', 
      'buyer_id' => 'Buyer', 
      'seller_id' => 'Seller', 
      'lta_product_id' => 'Lta Product', 
      'lta_contract_id' => 'Lta Contract', 
      'quantity' => 'Quantity', 
      'unitary_price' => 'Unitary Price', 
      'total_price' => 'Total Price', 
      'currency_id' => 'Currency', 
      'order_date' => 'Order Date', 
      'delivery_date' => 'Delivery Date', 
      'payment_date' => 'Payment Date', 
      'delivery_title' => 'Delivery Title', 
      'delivery_address' => 'Delivery Address', 
      'delivery_state' => 'Delivery State', 
      'delivery_city' => 'Delivery City', 
      'delivery_zip' => 'Delivery Zip', 
      'delivery_country_id' => 'Delivery Country', 
      'phone_number' => 'Phone Number', 
      'notes' => 'Notes', 
      'status' => 'Status', 
      'buyer_quota' => 'Buyer Quota', 
      'seller_quota' => 'Seller Quota', 
     ); 
    } 

添加在這樣的模型中,這「delivery_state」。

你們可以請建議我在哪裏,我錯了....

或任何東西我是缺少定義..

感謝

回答

0

您在main.php文件「的schemaCachingDuration」。如果它不是'0',則嘗試將其設置爲'0'。 在我的情況下,它的工作。

並且還添加'safe_'的'delivery_state'規則數組。它與錯誤無關,但它可以幫助您在提交表單時獲取所有屬性。

+0

在main.php文件中找不到schemaCachingDuration –

0

您應該修改數據庫以包含列delivery_state。但是,如果你不打算保存數據庫中的信息,你可以簡單地將其定義爲你的模塊的樣本

<?php 

class Delivery extends CActiveRecord 
{ 
    public $delivery_state; 
    /** 
    * @return string the associated database table name 
    */ 
    public function tableName() 
    { 
     return 'table-name'; 
    } 


} 
相關問題