[ASK] CGridView need help

hello i want to ask::

sorry before my english is not good ^^

I have a table

BSC

: Id, name, type

BSC_TYPE

: Id, name

foreing key bsc (type) references bsc_type (id)

in BSC-type display that’s its contents ID of BSC_TYPE

I want to display the [BSC TYPE] to [NAME of BSC_TYPE]

This example of my code








        $session=new CHttpSession;

                        $session->open();

                        

        $columns[]=array(

                'name'=>'name',

                'value'=>'$data->name',

                );

        $columns[]=array(

                'name'=>'desc',

                'value'=>'$data->desc',

                );

        $columns[]=array(

                'name'=>'type',

                'value'=>'$data->type',//<<the value i want to change

                );

        $columns[]=array(

                'name'=>'ip_address',

                'value'=>'$data->ip_address',

                );

        $columns[]=array(

                'name'=>'port',

                'value'=>'$data->port',

                );

        if($session['id'] != "")

        {

                if(Yii::app()->user->isAdmin())

                {

                        $columns[]=array(

                                'header'=>'Action',

                           'class'=>'CButtonColumn',

                        );

                }

                else

                {

                $columns[]=array(

                        'header'=>'Action',

                         'class'=>'CButtonColumn',

                        'template'=>'{view}',

                        'buttons'=>array

                        (

                        'view'=>array(

                                'label'=>'view',

                                'url'=>'Yii::app()->createUrl("Bsc/view", array("id"=>$data->id))',

                                        ),


                                ),      

                        );

                }

        }


        $this->widget('zii.widgets.grid.CGridView', array(

        'id'=>'bsc-grid',

        'dataProvider'=>$model->search(),

        'filter'=>$model,

        //'cssFile'=>false,

        'columns'=>$columns,

));






somebody please help me…^^

define a relation in your BSC model (check for public function relations()) -


'type'=>array(self::BELONGS_TO, 'BSC_TYPE', 'type')

now change your code -





        $columns[]=array(

                'name'=>'type',

                'value'=>'@$data->type->name',//<<the value i want to change



thank you for replying

I have tried your code, I do not get an error, but the result is empty in cgridview.why??


'type'=>array(self::BELONGS_TO, 'BscType', 'type')

<<using the model name right?but i tried to use the table name and model name and get the same result…

Yes, the model class name should be used.

Do have the model BscType defined? Is the grid completely empty or only the type column?

i use this code and successfully


'BscType'=>array(self::BELONGS_TO, 'BscType', 'type')

thanks Mukesh for your time…^^

I want to ask something:

I want to create a page that contains all users currently logged into my web.

and I can KICK to users who are logged.

  1. how to get all users currently logged into my web? or there extesion for this process