I have 2 tables
-
users
-
coupons
I have a form in my “coupons” view in which I want to search users after some filtration but I get error
Property "CDataColumn.username" is not defined.
This is in my Coupons Model class
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(
'users' => array(self::MANY_MANY, 'Users', 'allocated_coupons(coupons_id, users_id)'),
'zone' => array(self::BELONGS_TO, 'Zone', 'zone_id'),
'countries' => array(self::BELONGS_TO, 'Countries', 'countries_id'),
'invoices' => array(self::HAS_MANY, 'Invoice', 'coupons_id'),
'pricingPlans' => array(self::MANY_MANY, 'PricingPlans', 'pricing_plans_has_coupons(coupons_id, pricing_plans_id)'),
);
}
And also some editing in Coupons model Search function
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array( 'users' );
$criteria->together = true;
$criteria->compare( 'users.username', $this->users_search, true );
$criteria->compare( 'users.id', $this->users_search, true );
…………
Also some editing in rules() in Coupons model class
public $users_search;
public function rules()
{
array('users_search', 'safe', 'on'=>'search'),
In my search widget in view I use this
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'coupons-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'issue_date',
'start_date',
'expiry_date',
'count_value',
'code',
array( 'username'=>'users_search', 'value'=>'$data->users->username' ),