Ihab
Ihab

Reputation: 28

Yii customized CGridView undefined constant

I am new to Yii, I have the follwing code, 'columns'=>array( 'id', 'name', 'email', array( 'name' => 'deleted', 'value' => $model->deleted == 1 ? 'Yes' : 'No', ), I want to display YES if the deleted field from the database equal 1 or NO if not. and it keeps giving me a PHP notice : Use of undefined constant Yes. Thanks in advance.

EDIT My hole wedgit

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
    'id',
    'name',
    'email',
    array(
        'name' => 'deleted',


    ),
    /*
    'pass',
    'salt',

    'first',
    'last',
    'phone',
    'attempts',
    'locked',
    'gender',
    'birth',
    'joined',
    'updated',
    'active',
    'reset',
    'permission',
    'appress',
    'deleted',
    */
    array(
        'class'=>'CButtonColumn',
        'template'=>'{view}{ban}',
        'buttons' => array(
            'ban' => array
            (
            'label'=> 'Ban User',
            'url'=>'Yii::app()->createUrl("users/delete", array("id"=>$data->id))' ,

             'click'=>'function(){confirm("Are you sure you want to Ban this ?");}',
            ),
        )
    ),
),

));

Upvotes: 0

Views: 1199

Answers (2)

dInGd0nG
dInGd0nG

Reputation: 4114

Try this

'columns'=>array(
    'id', 
    'name',
    'email',
    array(
        'name' => 'deleted', 
        'value' => '$data->deleted == 1 ? "Yes" : "No"',
     ),
)

OR the YII way

'columns'=>array(
        'id', 
        'name',
        'email',
        'deleted:boolean'
    )

Upvotes: 4

devBinnooh
devBinnooh

Reputation: 611

At value section, You are trying to specify whether $model->deleted or not! if that's the case, then provide a boolean expression before '?'

Assuming that deleted returns 1 for true and otherwise for false; EX:

'columns'=>array( 'id', 'name', 'email', array( 'name' => 'deleted', 
  'value' => $model- >deleted == 1 ? 'Yes' : 'No', ),

Upvotes: 0

Related Questions