Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Trying To Get Property Of Non-Object

$
0
0
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);                     
        
        $dataProvider2 = News::model()->findByPk($dataProvider1->menu_id); //I want to get news is based on menu_id but ERROR HERE
        
        
        
        $this->render('category', array(
            'dataProvider' => $dataProvider,
            'dataProvider1' => $dataProvider1,
            'dataProvider2' => $dataProvider2,            
            '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="title"><a href="#"><?php echo $value->name ?></a></div>
              <div class="new-right-content"> 
                  <?php
                      foreach($dataProvider2 as $k=>$value){?>
                         <img src="<?php echo $baseUrl . '/' .'upload'.'/'. $value->image ?>" />
                         <h3><a href="#"><?php echo $value->title ?></a></h3>
                  <?php }?> 
                                                                                                
           </div>        
<?php }?>


Hope you help.thanks

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>