Its simple to set the active, inactive in the C detail View dropdown list, just assign the status value as like the below format
array(
'label'=>'Status',
'type'=>'raw',
'value'=>($model->status == 1) ? "Active" : "Inactive",
),
Showing posts with label YII. Show all posts
Showing posts with label YII. Show all posts
Thursday, 6 March 2014
CActiveDataProvider Yii - Is simple and neat
Labels:
YII
CActiveDataProvider Yii - Is simple and neat, where we can enter our condition, pagination etc
I actually started coding with custom select query in YII, but while referred to "CActiveDataProvider" with conditions and pagination there is no need for to call the sql query second time with condition or pagination
Here i will explain what i had previously and how the YII default CActiveDataProvider is working
My custom code in my controller function:
===========================================
public function actionList()
{
$criteria = new CDbCriteria();
$criteria->addCondition('user_id='.Yii::app()->user->id.'');
$count = Blog::model()->count($criteria);
$pages = new CPagination($count);
$pages->pageSize = 5;
$pages->applyLimit($criteria);
$models = Blog::model()->findAll($criteria);
$this->render('list', array('models' => $models, 'pages' => $pages));
}
While following the above code, i need to call this $model inside a foreach and need to show the values.
YII default CActiveDataProvider in my controller function:
===========================================
public function actionList()
{
$criteria=new CDbCriteria;
$criteria->order='id DESC';
$dataProvider=new CActiveDataProvider('Blog',array('criteria'=>$criteria,'pagination' => array('pageSize'=>Yii::app()->params['PaginationPerPage']),));
$this->render('list',array('dataProvider'=>$dataProvider,));
}
This is what Yii gave in default, its simple. And while following this code we can simply use the default view format from YII like below
$this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider,'itemView'=>'_view',));
?>
Wednesday, 5 February 2014
How to set the active and inactive status for 1,0 values in YII CGridView
Labels:
YII
In Yii normal CGridView will have the below structure
'columns'=>array(
'id',
'title',
'sstatus',
So to set the 0 as Inactive and 1 as Active
we need to edit the 'status' as
array(
'header'=>'status', //for to set the title for the table column, we can remove this if we need to show the default value
'name'=>'sstatus' // where sstatus is my database column name
'value'=>'($data->sstatus==1)? "Active" : "Inactive"'
),
Once set we can see 0 as inactive and 1 as active.
But how about filtering?
The filtering in Yii will work when we input 1 and not as active, so just replace this filter area with dropdown list in the same area where we updated our above code, just add filter array like below
array(
'header'=>'status', //for to set the title for the table column, we can remove this if we need to show the default value
'name'=>'sstatus' // where sstatus is my database column name
'value'=>'($data->sstatus==1)? "Active" : "Inactive"',
'filter'=>CHtml::dropDownList('Slider[sstatus]', 'sstatus',
array(
''=>'All',
'1'=>'Active',
'0'=>'Inactive',
)
),
),
),
in the above Slider is my model name and sstatus is my database table column... thats it.......
But i faced some problems like auto select and select all is not working, so we can set the filter directly like the below code
array(
'name' => 'sstatus',
'filter' => array(0 => 'In Active', 1 => 'Active'),
'value' => '($data->sstatus == 1) ? "Active" : "Inactive"',
),
'columns'=>array(
'id',
'title',
'sstatus',
So to set the 0 as Inactive and 1 as Active
we need to edit the 'status' as
array(
'header'=>'status', //for to set the title for the table column, we can remove this if we need to show the default value
'name'=>'sstatus' // where sstatus is my database column name
'value'=>'($data->sstatus==1)? "Active" : "Inactive"'
),
Once set we can see 0 as inactive and 1 as active.
But how about filtering?
The filtering in Yii will work when we input 1 and not as active, so just replace this filter area with dropdown list in the same area where we updated our above code, just add filter array like below
array(
'header'=>'status', //for to set the title for the table column, we can remove this if we need to show the default value
'name'=>'sstatus' // where sstatus is my database column name
'value'=>'($data->sstatus==1)? "Active" : "Inactive"',
'filter'=>CHtml::dropDownList('Slider[sstatus]', 'sstatus',
array(
''=>'All',
'1'=>'Active',
'0'=>'Inactive',
)
),
),
),
in the above Slider is my model name and sstatus is my database table column... thats it.......
But i faced some problems like auto select and select all is not working, so we can set the filter directly like the below code
array(
'name' => 'sstatus',
'filter' => array(0 => 'In Active', 1 => 'Active'),
'value' => '($data->sstatus == 1) ? "Active" : "Inactive"',
),
Subscribe to:
Posts (Atom)