Creating A Side-Bar Category List

I have a two-column layout and would-like to place category list (blog alike system) in the right sidebar. Yii blog demo suggests that I do it using portlets, but it generates lots of HTML I don’t actually need. All I want is <ul>* based list of categories.

What is the best Yii-practice to do that?

Dear Friend

I do not know whetther following is a good practice.

Kindly check this.

views/layouts/column2.php





<?php $this->beginContent('//layouts/main'); ?>

<div class="span-19">

	<div id="content">

		<?php echo $content; ?>

	</div><!-- content -->

</div>

<div class="span-5 last">

	<div id="sidebar">

	<?php

		$this->beginWidget('zii.widgets.CPortlet', array(

			'title'=>'Operations',

		));

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

			'items'=>$this->menu,

			'htmlOptions'=>array('class'=>'operations'),

		));

		$this->endWidget();

		$this->renderPartial("//layouts/list");//this is the added line.

	?>

	</div><!-- sidebar -->

</div>

<?php $this->endContent(); ?>




Now I have

views/layouts/list.php





<ul>

<li>apple</li>

<li>orange</li>

<li>banana</li>

<li>grapes</li>

</ul>


Regards.




Thanks for quick answer, but I need my category list to be loaded from database, not static list.

Dear Friend

Then that is the case, then I go for portlets.

Anyway we can do this.




$this->renderPartial("//layouts/list",array("fruits"=>Fruit::model()->findAll()));



Then in list.php




<ul>

<?php foreach ($fruits as $fruit) { ?>

<li><?php echo $fruit->name; ?></li>

<?php } ?>

</ul>



simple enough you don’t have to use what yii gives you out of the box just loop thru the array




example

<ul>

<?php foreach(Fruit::model()->findAll() as $f): ?>

    <li><?php $f->name></li>

<?php endforeach; ?>

</ul>

seenivasan, alirz23

Thanks for the answers. It’ll work fine for me.