Hello friend
I got an error followed by Trying to get property of non-object
I have 2 table: news and menu
My Controller:
$menu = Menu::model()->findByAttributes(array('alias' => $_GET['alias']))
$criteria1 = new CDbCriteria();
$criteria1->select='*';
$criteria1->condition = 'status=1 AND root_id=' . $menu->menu_id;
$criteria1->order = 'menu_id DESC';
$criteria1->limit = 2;
$dataProvider1 = Menu::model()->findAll($criteria1);
$this->render('category', array(
'dataProvider' => $dataProvider,
'dataProvider1' => $dataProvider1,
'menu' => $menu
));
New model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'menu' => array(self::BELONGS_TO, 'Menu','menu_id'),
);
}
Menu mode:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'news' => array(self::HAS_MANY, 'News','menu_id'),
);
}
My View:
<?php
foreach($dataProvider1 as $k =>$value){?>
<div class="news-right">
<div class="title"><a href="#"><?php echo $value->name ?></a></div>
<div class="new-right-content">
<?php
$news = News::model()->findByPk($value->menu_id);?>
<img src="<?php echo $baseUrl . '/' .'upload'.'/'. $news->image ?>" /> ERROR HERE
<h3><a href="#"><?php echo $news->title ?></a></h3>
</div>
</div>
<?php }?>
Hope you help.thanks