Still get Bug #1050: Fixed the bug that filter conditions were prefilled with default values when using an AR model in CGridView (Qiang)


(Dragon Html) #1

1.1.3




CREATE TABLE `obc_arpricetab` (

	`arprb_key` SMALLINT(10) NOT NULL AUTO_INCREMENT,

	`arprb_code` VARCHAR(16) NOT NULL,

	`arprb_name` VARCHAR(60) NOT NULL,

	`arprb_vattio` TINYINT(3) NOT NULL,

	`arprb_enabled` CHAR(1) NOT NULL DEFAULT 'Y',

	`arprb_remark` TEXT NULL,

	`arprb_default` CHAR(1) NOT NULL DEFAULT 'N',

	PRIMARY KEY (`arprb_key`)

)

ENGINE=InnoDB



admin.php




<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'obc-arpricetab-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'arprb_key',

		'arprb_code',

		'arprb_name',

/*		'arprb_vattio',

		'arprb_enabled',

		'arprb_remark',

		'arprb_default',

		*/

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



model




<?php


/**

 * This is the model class for table "obc_arpricetab".

 */

class ObcArpricetab extends CActiveRecord

{

	/**

	 * The followings are the available columns in table 'obc_arpricetab':

	 * @var integer $arprb_key

	 * @var string $arprb_code

	 * @var string $arprb_name

	 * @var integer $arprb_vattio

	 * @var string $arprb_enabled

	 * @var string $arprb_remark

	 * @var string $arprb_default

	 */


	/**

	 * Returns the static model of the specified AR class.

	 * @return ObcArpricetab the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'obc_arpricetab';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('arprb_code, arprb_name, arprb_vattio', 'required'),

			array('arprb_code, arprb_name', 'unique'),			

			array('arprb_vattio', 'numerical', 'integerOnly'=>true),

			array('arprb_code', 'length', 'max'=>16),

			array('arprb_name', 'length', 'max'=>60),

			array('arprb_enabled, arprb_default', 'length', 'max'=>1),

			array('arprb_remark', 'safe'),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('arprb_key, arprb_code, arprb_name, arprb_vattio, arprb_enabled, arprb_remark, arprb_default', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'obcArconditions' => array(self::HAS_MANY, 'ObcArcondition', 'arcd_arprb'),

			'obcPricelists' => array(self::HAS_MANY, 'ObcPricelist', 'arplu_arprb'),

			'obcPurchaseforcashhs' => array(self::HAS_MANY, 'ObcPurchaseforcashh', 'pch_arprb'),

			'obcPurchaserequeshes' => array(self::HAS_MANY, 'ObcPurchaserequesh', 'prh_arprb'),

			'obcQuatationhs' => array(self::HAS_MANY, 'ObcQuatationh', 'qth_arprb'),

			'obcSalescashhs' => array(self::HAS_MANY, 'ObcSalescashh', 'sch_arprb'),

			'obcSalesorderhs' => array(self::HAS_MANY, 'ObcSalesorderh', 'soh_arprb'),

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'arprb_key' => 'ลำดับ',

			'arprb_code' => 'รหัสตารางราคาสินค้า',

			'arprb_name' => 'ชื่อตารางราคาสินค้า',

			'arprb_vattio' => 'รวมภาษีแล้ว',

			'arprb_enabled' => 'สถานะการใช้งาน',

			'arprb_remark' => 'หมายเหตุ',

			'arprb_default' => 'เป็นตารางที่ใช้ประจำ',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('arprb_key',$this->arprb_key);


		$criteria->compare('arprb_code',$this->arprb_code,true);


		$criteria->compare('arprb_name',$this->arprb_name,true);


		$criteria->compare('arprb_vattio',$this->arprb_vattio);


		$criteria->compare('arprb_enabled',$this->arprb_enabled,true);


		$criteria->compare('arprb_remark',$this->arprb_remark,true);


		$criteria->compare('arprb_default',$this->arprb_default,true);


		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}

}



log




Querying SQL: SELECT * FROM `obc_arpricetab` `t` WHERE (arprb_enabled LIKE

:ycp0) AND (arprb_default LIKE :ycp1) LIMIT 10. Bind with parameter

:ycp0='%Y%', :ycp1='%N%'

in E:\Share2\277_ERP\framework\zii\widgets\CBaseListView.php (105)

in E:\Share2\277_ERP\framework\zii\widgets\grid\CGridView.php (220)

in E:\Share2\277_ERP\htdocs\protected\views\obcArpricetab\admin.php (60)




(Qiang Xue) #2

In your controller after creating the $model object, call $model->unsetAttributes(); // clear any default values


(Dragon Html) #3

Thank you, it’s already OK. :)