carraydataprovider annd sorting of related models

hi guys i am using carraydataprovider in my model to show the gridview bur i am stuck in sorting and searching of the fields

my model code is

<?php

/**

  • This is the model class for table "usergroups_modules".

  • The followings are the available columns in table ‘usergroups_modules’:

  • @property integer $id

  • @property string $display_name

  • @property integer $display_order

  • @property integer $parent_id

  • @property string $status

  • @property string $delete_flag

*/

class UserGroupsModulesNew extends CActiveRecord

{

/**


 * Returns the static model of the specified AR class.


 * @return UserGroupsModules the static model class


 */


 


 


public &#036;group_module_old;


public &#036;group_module;


public &#036;submoduleurl;


public &#036;submodule;


public &#036;moduleurl;


public &#036;module;


public &#036;thevalue; 


public &#036;usergroups_mainmodule; 


private &#036;_mainmodule = null;


public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}





/**


 * @return string the associated database table name


 */


public function tableName()


{


	 return Yii::app()-&gt;db-&gt;tablePrefix.'usergroups_modules';


}





/**


 * @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('display_name,moduleurl,submoduleurl,submodule', 'required'),


		array('group_module,group_module_old', 'GroupModule'),


		array('group_module', 'duplicacy'),


		


		


		


		


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


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


		


	);


}





/**


 * @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(


	);


}





public function allrequired()


{


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


	// class name for the relations automatically generated below.


	 &#036;w=0;


	&#036;j=0;


	


	for(&#036;i=1;&#036;i&lt;=&#036;_POST['UserGroupsModulesNew']['thevalue'];&#036;i++)


	{


		if(&#036;i==1)


		{


			&#036;j='';


		}


		else


		{


			&#036;j=&#036;i;


		}


		//&#036;submodule='submodule'.&#036;j;


		//echo &#036;this-&gt;&#036;submodule;


		//&#036;model-&gt;attributes=&#036;this-&gt;&#036;submodule;


		//if(&#036;this-&gt;&#036;submodule=='')


		//{


			


			// &#036;w=0;


		//	


		//}


		//else


		//{


			 &#036;w=1;


		//}


		


		


		


   }


 


   echo &#036;w;


   if(&#036;w==0)


   {


   	&#036;this-&gt;addError('submodule','Please Enter Sub Module');


	return false;


   }


   else


   {


   	return true;


   }


}





public function GroupModule()


{


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


	// class name for the relations automatically generated below.


	if(&#036;this-&gt;group_module=='' &amp;&amp; &#036;this-&gt;group_module_old=='')


	{


		&#036;this-&gt;addError('group_module_old','Please select group from the dropdown else enter new module');


		return false;


	}


	else if(&#036;this-&gt;group_module &amp;&amp; &#036;this-&gt;group_module_old)


	{


		&#036;this-&gt;addError('group_module_old','Please either select group from the dropdown or enter new module');


		return false;


	}


	else


	{


		return true;


	}


}





public function duplicacy()


{


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


	// class name for the relations automatically generated below.


	&#036;criteria=new CDbCriteria();


	&#036;criteria-&gt;condition='controller=:display_name and status=:status and delete_flag=:deleteflag';


	&#036;criteria-&gt;params=array(':display_name'=&gt;&#036;this-&gt;group_module,':status'=&gt;'1',':deleteflag'=&gt;'0');


	&#036;count=UserGroupsModulesNew::model()-&gt;count(&#036;criteria);





	if(&#036;count&gt;0)


	{


		&#036;this-&gt;addError('group_module','Group Module already Exists');


		return false;


	}


	


	{


		return true;


	}


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'id' =&gt; 'ID',


		'display_name' =&gt; 'Display Name',


		'display_order' =&gt; 'Display Order',


		'parent_id' =&gt; 'Parent',


		'status' =&gt; 'Status',


		'delete_flag' =&gt; 'Delete Flag'


	);


}





/**


 * 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.





	


	&#036;rawData='';


	&#036;rawData=Yii::app()-&gt;db-&gt;createCommand()


											-&gt;select('newmainmod.display_name as mainmodule,newmainmod.id as mainmoduleid,submod.display_name as submodule,submod.id as id')


											-&gt;from('usergroups_modules submod')


											-&gt;join('usergroups_modules newmainmod','submod.parent_id=newmainmod.id')


											-&gt;where(&quot;newmainmod.parent_id='0' and newmainmod.flag_level='0' and submod.flag_level='1'&quot;)


											-&gt;order(&quot;newmainmod.display_name desc&quot;)


											-&gt;queryAll();


	


	 &#036;sort = new CSort;


    &#036;sort-&gt;defaultOrder = 'submodule DESC';


    &#036;sort-&gt;attributes = array('submodule','usergroups_mainmodule');





	return new CArrayDataProvider(&#036;rawData, array( 'id'=&gt;'modulesmanagae','pagination'=&gt;array(


																		'pageSize'=&gt;10,


																	   ),


																	   'sort'=&gt;&#036;sort,


		));

}

}

it is throwing the error that usergroups_module is not defined and also the searching or filtering is not getting done i have made an additions class filtersmodel and the code is

<?php

class FiltersForm extends CFormModel

{

private &#036;_filters = array();


public function __get(&#036;name)


{if(&#33;array_key_exists(&#036;name, &#036;this-&gt;_filters))


        &#036;this-&gt;_filters[&#036;name] = null;





    return &#036;this-&gt;_filters[&#036;name];





}


public function filter(array &#036;data)


{


    foreach(&#036;data AS &#036;rowIndex =&gt; &#036;row) {


        foreach(&#036;this-&gt;filters AS &#036;key =&gt; &#036;value) {


            // unset if filter is set, but doesn't match


            if(array_key_exists(&#036;key, &#036;row) AND &#33;empty(&#036;value)) {


                if(stripos(&#036;row[&#036;key], &#036;value) === false)


                    unset(&#036;data[&#036;rowIndex]);


            }


        }


    }


    return &#036;data;


}

}

and the controller code related to this is

public function actionIndex()

{


	&#036;model=new UserGroupsModulesNew('search');


	&#036;filtersForm='';


	&#036;filtersForm=new FiltersForm;


	if (isset(&#036;_GET['FiltersForm']))


 	&#036;filtersForm-&gt;filters=&#036;_GET['FiltersForm'];


	&#036;this-&gt;render('index',array('model'=&gt;&#036;model,'FiltersForm'=&gt;&#036;filtersForm));


}

and the view code is

<?php

$this->breadcrumbs=array(

'Modules',

);?>

<?php if(Yii::app()->user->hasFlash(‘group’)):?>

&lt;div class=&quot;info&quot;&gt;


    &lt;?php echo Yii::app()-&gt;user-&gt;getFlash('group'); ?&gt;


&lt;/div&gt;

<?php endif; ?>

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

'dataProvider'=&gt;&#036;model-&gt;search(),





'filter'=&gt;&#036;FiltersForm,


'columns'=&gt;array(


	


	array('name'=&gt;'submodule','type'=&gt;'raw','value'=&gt;'&#036;data[&quot;submodule&quot;]'),


	array('header'=&gt;'Main module','name'=&gt;'usergroups_mainmodule','type'=&gt;'raw','value'=&gt;'&#036;data[&quot;mainmodule&quot;]', ),


	 array('class'=&gt;'CButtonColumn',


		'template'=&gt;'{view}{delete}{update}',


		'header'=&gt;'Actions',


		


		'afterDelete'=&gt;'function(link,success,data){ if(success) alert(&quot;Delete completed successfuly&quot;); }',


		


		 'viewButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/modules/test&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


		  'deleteButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/modules/delete&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


  		'updateButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/modules/update&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',),





	),

)); ?>

Please help me out i am stuck in this issue i have searched out every single forum but nothing helped…please guysssssssssssssssssssss

yipee i solved by changing some of the things like i added in the filtersmodel

public function filter($data)

{


    &#036;temp = &#036;data-&gt;getData();





    foreach (&#036;temp AS &#036;index =&gt; &#036;item)


    {


        foreach (&#036;this-&gt;filters AS &#036;key =&gt; &#036;value)


        {


            if(&#036;value == '') continue; // bypass empty filter





            &#036;test = false;  // value to test for





            if(&#036;item instanceof CModel)


            {


                if(isset(&#036;item-&gt;&#036;key) == false ) throw new CException(&quot;Property &quot;.get_class(&#036;item).&quot;::{&#036;key} does not exist&#33;&quot;);


                &#036;test = &#036;item-&gt;&#036;key;


            }


            elseif(is_array(&#036;item))


            {


                if(&#33;array_key_exists(&#036;key, &#036;item)) throw new CException(&quot;Key {&#036;key} does not exist in Array&#33;&quot;);


                &#036;test = &#036;item[&#036;key];


            }


            else


                throw new CException(&quot;Data in CArrayDataProvider must be an array of arrays or CModels&#33;&quot;);





            if(stripos(&#036;test, &#036;value) === false)


                unset(&#036;temp[&#036;index]);


        }


    }





    &#036;data-&gt;setData(array_values(&#036;temp));


    return &#036;data;


}

and changed my controller to

public function actionIndex()

{


	&#036;model=new UserGroupsModulesNew('search');


	&#036;filtersForm='';


	&#036;filtersForm=new FiltersForm;


	if (isset(&#036;_GET['FiltersForm']))


 	&#036;filtersForm-&gt;filters=&#036;_GET['FiltersForm'];


	&#036;dataprovider= &#036;filtersForm-&gt;filter(&#036;model-&gt;search());


	&#036;this-&gt;render('index',array('model'=&gt;&#036;model,'FiltersForm'=&gt;&#036;filtersForm,'dataprovider'=&gt;&#036;dataprovider));


}

and changed my view to

<?php

$this->breadcrumbs=array(

'Modules',

);?>

<?php if(Yii::app()->user->hasFlash(‘group’)):?>

&lt;div class=&quot;info&quot;&gt;


    &lt;?php echo Yii::app()-&gt;user-&gt;getFlash('group'); ?&gt;


&lt;/div&gt;

<?php endif; ?>

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

'dataProvider'=&gt; &#036;dataprovider,


'filter'=&gt;&#036;FiltersForm,


'columns'=&gt;array(


	


	array('name'=&gt;'submodule'),


	array('header'=&gt;'Main module','name'=&gt;'usergroups_mainmodule'),


	 array('class'=&gt;'CButtonColumn',


		'template'=&gt;'{view}{update}{delete}',


		'header'=&gt;'Actions',


		


		'afterDelete'=&gt;'function(link,success,data){ if(success) alert(&quot;Delete completed successfuly&quot;); }',


		


		 'viewButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/modules/test&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


		  'updateButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/modules/update&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


		  'deleteButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/modules/delete&quot;, array(&quot;id&quot; =&gt; &#036;data[&quot;id&quot;]))',


		 





	)),

)); ?>

it enables all the sorting and filtering