Yii Framework Forum: CWidget problem - Yii Framework Forum

Jump to content

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

CWidget problem Rate Topic: -----

#1 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 26 February 2010 - 04:10 AM

I made a CWidget and I call is as below and I have the error Property "upMenu.items" is not defined,what is wrong?
<?php   $this->widget('upMenu',array(
			'items'=>Cats::model()->getUpmenu())) ?>

<?php
<ul>
<?php  $i=0;  foreach($items as $comment): ?>

<li <?php if ($i++==0) {?> class="first"<?php }?>>
	<?php echo CHtml::link(CHtml::encode($comment['cat_name']),array('site/index','code'=>$comment['cat_code'])); ?>
</li>
<?php endforeach; ?>
<li><?php echo CHtml::link('Contact',array('site/contact')); ?></li>
</ul>
......
class upMenu extends CWidget
{  
    public function init()
    { parent::init();
      
        // this method is called by CController::beginWidget()
    }

    public function run()
    {
        // this method is called by CController::endWidget()
    }
protected function renderContent()
	{
		$this->render('upMenu');
	}
public function getMenu()
	{
		return Cats::model()->getUpmenu();
	}
}
?>

Posted Image
0

#2 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 26 February 2010 - 04:15 AM

I make a variable public $items at the Widget but now nothing return the Widget what is wrong?
Posted Image
0

#3 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 26 February 2010 - 04:19 AM

I solved writing this
<?php
class upMenu extends CWidget
{
public $items=array();
    public function init()
    {
        parent::init();
      
        // this method is called by CController::beginWidget()
    }

    public function run()
    {
       $this->render('upMenu',array ('items'=>$items));
    }

public function getMenu()
	{
		return Cats::model()->getUpmenu();
	}
}
?>

Posted Image
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