Admin View From Single Item View.

Hello,

I want to show belong item view data a view similar to admin view.

So in this item view (protected/views/assistant/view.php), after zii.widgets.CDetailView I call to zii.widgets.grid.CGridView with dataProvider from CArrayDataProvider.

Everything look great, my problem is when I want to use some function from other model.

I have an "activity_type" in the table, which is a integer, but I want to show not the number but the associate name.

So in Activity model there is 2 functions:




        public function getTypeOptions()

        {

                return array(

                        self::TYPE_BOARDGAME => 'Boardgame',

                        self::TYPE_CARDGAME => 'Cardgame',

                        self::TYPE_ROLE => 'Role',

                        self::TYPE_KIDS => 'Kids',

                );

        }


        public function getTypeText()

        {

                $typeOptions = $this->typeOptions;

                return isset($typeOptions[$this->activity_type]) ? $typeOptions[$this->activity_type] : "unknown type ({$this->activity_type})";

        }



I call this function with:




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

        'dataProvider'=>$dataProviderAA,

        'columns'=>array(

                array(

                        'header' => 'Activity',

                        'name' => 'activity_name',

                        'type' => 'raw',

                        'value'=>'CHtml::link($data["activity_name"],array("activity/view","id"=>$data["activity_id"]))',

                ),

                array(

                        'header' => 'Type',

                        'name' => 'activity_type',

                        'value' => Activity::getTypeText($data["activity_type"]),

                ),

                ...



I think the call is done fine, but “getTypeText”, call itself another function inside Activity model, but when it try to call it, it doesn’t search inside Activity model but Assistant, because i got the following CException:

And it show me "getTypeText" with "$typeOptions = $this->typeOptions;" remarked.

Do you know how I should call "getTypeText" in this context ?

Thanks.

I found the solution:

I had to define colum value with:




'value' => 'Activity::model()->getTypeText($data["activity_type"])',



And then fix the function to get parameters from outside:




        public function getTypeText($activity_type = null)

        {

                if($activity_type != null) $this->activity_type = $activity_type;

                $typeOptions = $this->typeOptions;

                return isset($typeOptions[$this->activity_type]) ? $typeOptions[$this->activity_type] : "unknown type ({$this->activity_type})";

        }


Now everything work fine <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />


Thanks.