Searching And Sorting From 2 Models

I have 2 tables

  1. users

  2. 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( '', $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(











		 array( 'username'=>'users_search', 'value'=>'$data->users->username' ),

it is because you have:

array( 'username'=>'users_search', 'value'=>'$data->users->username' ),

in your widget definition.

it should be:

array( 'name'=>'users_search', 'value'=>'$data->users->username' ),

I only need filtered users from Users model in coupons view. I use this code and Users data shown in Grid, but filter not working

$model2 = new Users('search');

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

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

'filter' => $model2,

'columns' => array(



            'id' => 'selectedIds',

            'class' => 'CCheckBoxColumn',

                        'selectableRows' =>'2',