如何将新属性添加到模型yii框架?

时间:2016-10-21 13:09:25

标签: php yii

我在表'delivery_state'

中添加了一个新列

并在yii框架中使用它。

我在下面的函数

中将这个'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'但是我收到了错误消息属性delivery_state没有定义。

你能告诉我我错在哪里吗?

或者我想要定义的任何东西..

由于

2 个答案:

答案 0 :(得分:0)

检查main.php文件中的'schemaCachingDuration'。如果不是'0'则尝试将其设为'0'。 就我而言,它有效。

并添加'deliver_state'规则数组'safe'。它与错误无关,但它可以帮助您在提交表单时获取所有属性。

答案 1 :(得分:0)

您应修改数据库以包含列delivery_state。但是,如果您不打算在db中保存信息,则可以将其定义为您的模块的主要内容

<?php

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


}