Cgridview Button Url To Many Views

Hello.

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:

http://pastebin.com/fcUZzMd4

Thanks for help

Greetings

Tom

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';

   else

     $url = 'observationsMammals/view';


   return $url;

}



Then set URL In your CGridView:




array(

   'class'=>'CButtonColumn',

   '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:


'url'=>'$data->getLink()'



Thanks for suggestions:)

hi friends you can try

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

'id'=>'followups-grid',


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


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


//'filter'=>$model,


'columns'=>array( 


    array(


        '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',


        'header'=>false,


        'filter'=>false,


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


    ),





    //'INTERNAL_MESSAGE',





    array(


        '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'


    'buttons'=>array(


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


        array('items'=>array(


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


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


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


            '---',


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


        )),


    ),


), true) ;

}