Yii Framework Forum: Get Data From Another Table(Mapping Table) - Yii Framework Forum

Jump to content

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

Get Data From Another Table(Mapping Table) there is a mapping table ,and i want to show this data on Index page. Rate Topic: ***** 1 Votes

#1 User is offline   shivanshu 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 17-March 13
  • Location:India

Posted 15 April 2013 - 05:50 AM

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.

Attached File(s)

  • Attached File  yii.png (11.69K)
    Number of downloads: 13

0

#2 User is offline   johnsnails 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 05-September 11
  • Location:Sydney Australia

Posted 15 April 2013 - 07:45 AM

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/
0

#3 User is offline   shivanshu 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 17-March 13
  • Location:India

Posted 15 April 2013 - 12:39 PM

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.
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