Property Is Not Defined

Hello friend

I got an error followed by Property "News.name" is not defined.

I have 2 table: news and menu

My Controller:




        $menu = Menu::model()->findByAttributes(array('alias' => $_GET['alias']));


        $criteria1 = new CDbCriteria();

        $criteria1->select='t.*';                       

        $criteria1->with = array('menu'=>array('select'=>'menu.name'));

        $criteria1->join = 'join menu on t.menu_id = menu.menu_id';            

        $criteria1->condition = 't.status=1 AND menu.root_id=' . $menu->menu_id;

        $criteria1->order = 'menu.menu_id DESC';

        $criteria1->limit = 2;

        

        $dataProvider1 = News::model()->findAll($criteria1);


         $this->render('category', array(            

            '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 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(

            '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>  ERROR HERE

              <div class="new-right-content">                         

                  <img src="<?php echo $baseUrl . '/' .'upload'.'/'. $value->image ?>" />

                                <h3><a href="#"><?php echo $value->title ?></a></h3>

                                                                                                                              </div> 

           </div>

       <?php }?>



Hope you help.thanks

you can’t access $menu name directly from $news model you have to do it thru the associations


 <?php foreach($dataProvider1 as $k =>$value){?>                                                             

           <div class="title"><a href="#"><?php echo $value->name ?></a></div>  // should be $value->menu->name

              <div class="new-right-content">                         

                  <img src="<?php echo $baseUrl . '/' .'upload'.'/'. $value->image ?>" />

                                <h3><a href="#"><?php echo $value->title ?></a></h3>

                                                                                                                              </div> 

           </div>

<?php }?>

name of the menu table.After edit:$value->menu->name, I get an error SQL: Not unique table/alias: ‘menu’

Can you help me check the query in Controller?




        $criteria1->with = array('menu'=>array('select'=>'menu.name'));

        $criteria1->join = 'join menu on t.menu_id = menu.menu_id';



These do exactly the same thing. Remove the second line :)

thank you very much !!!