Get Data From Another Table(Mapping Table)

Hi guys,

Having a problem and i believe you will help me .Thanks in advance.

Here is my problem

On Index page i have a checkboxlist an i want it to be filled when index page loads.See the attached file.

I am thinking to do it either of two ways.

1)first create a join query here

public function actionIndex()

{


	$this->dataProvider=new CActiveDataProvider('Media',array(


                                'criteria'=>array('order'=>'id DESC')));

2)call a controller method in CActiveDataProvider.

Please suggest me the best way or how can i create a join query.

Have a look at “lazy loading”. Lazy loading triggers Yii to perform a

relational query on demand:




// Perform one query of the comment table:

$comment = Comment::model()->findByPk(1);


// Run another query to get the associated username:

$user = $comment->user->username;



OR better yet "eager loading"




// Perform one query of the comment table:

$comment = Comment::model()->with('user')->findByPk(1);

// No query necessary to do this:

$user = $comment->user->username;



This does assume I believe that you have set up your relations correctly (which if you did in your DB model and used gii, that should be the case.

Source

The Yii Book

http://yii.larryullman.com/

i am getting data in dataprovider but i dont know how to use it.

public function actionIndex()

{


            $criteria = new CDbCriteria();


            $criteria->order= 'id DESC';


            $criteria->with = array('tblGenres');


	


            $this->dataProvider=new CActiveDataProvider('Media',array(


                                'criteria'=>$criteria,//array('order'=>'id DESC')


                                ));





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


		'dataProvider'=>$this->dataProvider,


	));


}

And this is my Checkboxlist in _view page.

<?php echo CHtml::CheckBoxList(‘genre’,$data->genreId,CHtml::listData(Genre::model()->findAll(),‘id’,‘genre_name’)); ?>

How to use $data->genre or may be $data->genreId .In this checkbox list.