Yii Framework Forum: Cdetailview - Create Link To Another Model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cdetailview - Create Link To Another Model Rate Topic: -----

#1 User is offline   Wayde 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-July 14

Posted 04 July 2014 - 10:48 AM

Hi All,
Learning Yii here for my next project. I have managed to display the related data of a model as seen below. but i want to make the "'value' => $show," a link to the related model view. I tried placing CHtml::link('name', 'link') in many parts of the below but in the view, it shows the tags eg. <a href=""> </a> instead of making the link. any help would be amazing! Thanks!

 <?php

$descs = array();
foreach($model->shows as $shows)
{
    $descs[] = $shows->Show_name;
	$id[] = $shows->ID;
}
$show = implode(', ', $descs);

$this->widget('zii.widgets.CDetailView', array(
    'data'=>$model,
    'attributes'=>array(
        array(
            'name' => 'Shows',
          'value' => $show,
		  )
	
    )
));

?>

0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 751
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 04 July 2014 - 11:46 AM

append "type"=>"raw" after "value" or before

 <?php

$descs = array();
foreach($model->shows as $shows)
{
    $descs[] = $shows->Show_name;
        $id[] = $shows->ID;
}
$show = implode(', ', $descs);

$this->widget('zii.widgets.CDetailView', array(
    'data'=>$model,
    'attributes'=>array(
        array(
            'name' => 'Shows',
            'value' =>  CHtml::link('name', 'link') ,
            'type'=>'raw'
         )
        
    )
));

?>

0

#3 User is offline   Wayde 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-July 14

Posted 04 July 2014 - 12:04 PM

Thanks for your quick reply! It worked, but it linked all the related data in one big link so i moved the link to be set in $descs see code below. Its the result i needed! Thanks again!

<?php

$descs = array();
foreach($model->shows as $shows)
{   $id = $shows->ID;
    $descs[] = CHtml::link($shows->Show_name, array('shows/view', 'id' => $id));
}
$show = implode(', ', $descs);

$this->widget('zii.widgets.CDetailView', array(
    'data'=>$model,
    'attributes'=>array(
        array(
          'name' => 'Shows',
          'value' => $show,
		  'type' => 'raw')
	
    )
));

?>

0

#4 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 751
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 04 July 2014 - 01:41 PM

np glad could help. it looks ok
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users