Yii Framework Forum: Creating A Side-Bar Category List - Yii Framework Forum

Jump to content

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

Creating A Side-Bar Category List Rate Topic: -----

#1 User is offline   mr_goodcat 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 14-January 13

Posted 14 January 2013 - 02:04 AM

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?
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

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

<?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.


1

#3 User is offline   mr_goodcat 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 14-January 13

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.
0

#4 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 14 January 2013 - 02:49 AM

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>

0

#5 User is offline   alirz23 

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

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>

0

#6 User is offline   mr_goodcat 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 14-January 13

Posted 15 January 2013 - 12:47 AM

seenivasan, alirz23

Thanks for the answers. It'll work fine for me.
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