php - Show cgridview data based on condition

485

Is this possible to show cgridview data using condition. like only show those data where status=1.

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-details-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
    'id',
    'name1',
    'p_address1',
    'phoneno',
    'email1',
    'owner_name',
    'position', 
    'status'
    array(
        'class'=>'CButtonColumn',
        'template'=>'{delete}',

     ),
),

));

The table have status 0 and 1. I only want those listings which status is 1.

UPDATE: if i changed search method like this

$criteria->compare('status',1);

It's worked perfectly. But is it a good practice?

632

Answer

Solution:

You show data from model in CGridView. You can add conditions as criteria. For example in your model in search method add

$criteria->addCondition('status = 1');

People are also looking for solutions to the problem: php - Smarty: cannot replace string

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.