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?
Page 1 of 1
Creating A Side-Bar Category List
#2
Posted 14 January 2013 - 02:27 AM
Dear Friend
I do not know whetther following is a good practice.
Kindly check this.
views/layouts/column2.php
Now I have
views/layouts/list.php
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.
#3
Posted 14 January 2013 - 02:38 AM
Thanks for quick answer, but I need my category list to be loaded from database, not static list.
#4
Posted 14 January 2013 - 02:49 AM
Dear Friend
Then that is the case, then I go for portlets.
Anyway we can do this.
Then in list.php
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>
#5
Posted 14 January 2013 - 06:03 AM
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>
#6
Posted 15 January 2013 - 12:47 AM
seenivasan, alirz23
Thanks for the answers. It'll work fine for me.
Thanks for the answers. It'll work fine for me.
Share this topic:
Page 1 of 1