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 $group_module_old;
public $group_module;
public $submoduleurl;
public $submodule;
public $moduleurl;
public $module;
public $thevalue;
public $usergroups_mainmodule;
private $_mainmodule = null;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return Yii::app()->db->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.
$w=0;
$j=0;
for($i=1;$i<=$_POST['UserGroupsModulesNew']['thevalue'];$i++)
{
if($i==1)
{
$j='';
}
else
{
$j=$i;
}
//$submodule='submodule'.$j;
//echo $this->$submodule;
//$model->attributes=$this->$submodule;
//if($this->$submodule=='')
//{
// $w=0;
//
//}
//else
//{
$w=1;
//}
}
echo $w;
if($w==0)
{
$this->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($this->group_module=='' && $this->group_module_old=='')
{
$this->addError('group_module_old','Please select group from the dropdown else enter new module');
return false;
}
else if($this->group_module && $this->group_module_old)
{
$this->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.
$criteria=new CDbCriteria();
$criteria->condition='controller=:display_name and status=:status and delete_flag=:deleteflag';
$criteria->params=array(':display_name'=>$this->group_module,':status'=>'1',':deleteflag'=>'0');
$count=UserGroupsModulesNew::model()->count($criteria);
if($count>0)
{
$this->addError('group_module','Group Module already Exists');
return false;
}
{
return true;
}
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'display_name' => 'Display Name',
'display_order' => 'Display Order',
'parent_id' => 'Parent',
'status' => 'Status',
'delete_flag' => '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.
$rawData='';
$rawData=Yii::app()->db->createCommand()
->select('newmainmod.display_name as mainmodule,newmainmod.id as mainmoduleid,submod.display_name as submodule,submod.id as id')
->from('usergroups_modules submod')
->join('usergroups_modules newmainmod','submod.parent_id=newmainmod.id')
->where("newmainmod.parent_id='0' and newmainmod.flag_level='0' and submod.flag_level='1'")
->order("newmainmod.display_name desc")
->queryAll();
$sort = new CSort;
$sort->defaultOrder = 'submodule DESC';
$sort->attributes = array('submodule','usergroups_mainmodule');
return new CArrayDataProvider($rawData, array( 'id'=>'modulesmanagae','pagination'=>array(
'pageSize'=>10,
),
'sort'=>$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 $_filters = array();
public function __get($name)
{if(!array_key_exists($name, $this->_filters))
$this->_filters[$name] = null;
return $this->_filters[$name];
}
public function filter(array $data)
{
foreach($data AS $rowIndex => $row) {
foreach($this->filters AS $key => $value) {
// unset if filter is set, but doesn't match
if(array_key_exists($key, $row) AND !empty($value)) {
if(stripos($row[$key], $value) === false)
unset($data[$rowIndex]);
}
}
}
return $data;
}
}
and the controller code related to this is
public function actionIndex()
{
$model=new UserGroupsModulesNew('search');
$filtersForm='';
$filtersForm=new FiltersForm;
if (isset($_GET['FiltersForm']))
$filtersForm->filters=$_GET['FiltersForm'];
$this->render('index',array('model'=>$model,'FiltersForm'=>$filtersForm));
}
and the view code is
<?php
$this->breadcrumbs=array(
'Modules',
);?>
<?php if(Yii::app()->user->hasFlash(‘group’)):?>
<div class="info">
<?php echo Yii::app()->user->getFlash('group'); ?>
</div>
<?php endif; ?>
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'dataProvider'=>$model->search(),
'filter'=>$FiltersForm,
'columns'=>array(
array('name'=>'submodule','type'=>'raw','value'=>'$data["submodule"]'),
array('header'=>'Main module','name'=>'usergroups_mainmodule','type'=>'raw','value'=>'$data["mainmodule"]', ),
array('class'=>'CButtonColumn',
'template'=>'{view}{delete}{update}',
'header'=>'Actions',
'afterDelete'=>'function(link,success,data){ if(success) alert("Delete completed successfuly"); }',
'viewButtonUrl'=>'Yii::app()->createUrl("/modules/test", array("id" => $data["id"]))',
'deleteButtonUrl'=>'Yii::app()->createUrl("/modules/delete", array("id" => $data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("/modules/update", array("id" => $data["id"]))',),
),
)); ?>
Please help me out i am stuck in this issue i have searched out every single forum but nothing helped…please guysssssssssssssssssssss