Display HAS_MANY relation in cDetailView

Hi, i want to display all "Artikels" belonging to my "Buch" in a cDetailView.

Sadly my values appear outside of the table. Don´t know how to fix this.

Please help.

Here is what i got:

models/Buch.php


public function relations()

	{

		return array(

			'artikels' => array(self::HAS_MANY, 'Artikel', 'buchId'),

		);

	}

and in my models/Artikel.php


public function relations()

	{

		return array(

			'buch' => array(self::BELONGS_TO, 'Buch', 'id'),

		);

	}

Now the part that doesn´t work (although I get the list with all Artikels, but outside of the cDetailView):


<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'id',

		'art.name',

		'isbn',

		'ausgabe',

		array(

			'name'=>'Artikel',

			'type'=>'html',

			'value'=>$model->relatedArtikel,

			//'value'=>CHtml::link(CHtml::encode($model->artikels->name),array('artikel/view','id'=>$model->artikels->id)),

			//'value'=>CHtml::listData(Artikel::model()->findAll(), 'id', 'name'),

		),

	),

)); ?>

and here my function getRelatedArtikel in models/Buch.php:


public function getRelatedArtikel ()

	{

	   $out=CHtml::listData($this->artikels,'id','name');

	   $ausgabe = '<ul>';

	   foreach($out as $key=>$value) { 

		$ausgabe .= printf('<li>%s</li>', CHtml::link($value, array('artikel/view', 'id' => $key)));

		

	   }

	   $ausgabe .= '</ul>';

	   return $ausgabe;

	}

Note: you should have <li> elements inside your <ul> element.

It was in my code before. Edited my post above. But problem still exists with the correct HTML.

You should use sprintf instead of printf.

/Tommy

You have a very good eye, Tommy :)

Thank you very much. That worked. Topic closed.