Cgridview Button Url To Many Views


How can i generate dynamic buttons urls to many views using one cgridview? For example. I have Observations controller in which i have observations of birds, mammals etc. When record belongs to birds i want to generate url to birds view: birds/view/id/, analogically - when i have records which belongs to mammals, i want to generate url link to view: mammals/view/id ?

here is my pastebin:

Thanks for help



Hi Tom,

The class model that is used in your CGridView is AllObservations, right? I think you can add a method like this to that class:

public function getUrl()


   // this would depend on how the application identifies species name

   if (strcasecmp($this->idSpecies->name, 'BIRD') == 0)

     $url = 'observationsBirds/view';


     $url = 'observationsMammals/view';

   return $url;


Then set URL In your CGridView:



   'viewButtonUrl'=>'Yii::app()->createUrl($data->getUrl(), array("id"=>$data->id))'


I haven’t tested it but if you have problem with that approach, please let us know. ;)

Thanks all for your replies. Answer was very simple:

in model: 

public function getLink()


if ($this->nazwa == 'Bird')


  $url= '/bird/' . $this->id ;  


return $url;


and in view:


Thanks for suggestions:)

hi friends you can try

$this->widget(‘bootstrap.widgets.TbGridView’, array(



'rowCssClassExpression' => '\'ticket-followup-\'.$data->ID',




        'name' => 'FOLLOWUP_MESSAGE',

        'value'=>   '"<div class=\"summery\">". split_words(CHtml::decode($data->FOLLOWUP_MESSAGE), 10). "</div>"

                        ."<div class=\"details hide\">".  CHtml::decode($data->FOLLOWUP_MESSAGE) . "</div>" 


        'type' => 'html',



        'htmlOptions'=>array('width'=>'90%', "id" => $model->ID, 'class'=>'followup-row content-area',),




        'name'          =>  'ENTRY_TIME', 

        'value' => 'btnWidget()',

        'type'          =>  'html',

        'header'        =>  false,

        'filter'        =>  false,

        'htmlOptions'   =>  array('width'=>'10%', "id" => '$row+1', 'class'=>'followup-row ',),




function btnWidget(){

$widget = new CWidget();

return $widget->widget('bootstrap.widgets.TbButtonGroup', array(

    'type'=>'info', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'


        array('label'=>'Action', 'url'=>'#'),


            array('label'=>'Action', 'url'=>'#'),

            array('label'=>'Another action', 'url'=>'#'),

            array('label'=>'Something else', 'url'=>'#'),


            array('label'=>'Separate link', 'url'=>'#'),



), true) ;