Yii Framework Forum: MANY_MANY CActiveDataProvider - Yii Framework Forum

Jump to content

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

MANY_MANY CActiveDataProvider Rate Topic: -----

#1 User is offline   gdang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 20-August 11
  • Location:Venice

Posted 29 August 2011 - 06:52 AM

buongiorno, sono nuovo di YII e pongo un questito particolarmente stupido al quale però nen trovo risposta :D

Ho 2 tebelle: Division e Person e sono correlate tra loro da una relazione MANY_MANY rispettivamente con Division.people e Person.divisions

vorrei utilizzare CActiveDataProvider per poi utilizzare una gridView per visionare tutte le persone che lavorano in una data Division.

per ora ho fatto:

	$dataProvider=new CActiveDataProvider('person', array(
		'criteria'=>array(
			'with'=>'divisions',
			'condition'=>'Division.id=23',
		),
		'pagination'=>array(
			'pageSize'=>20,
		),
		)
	);


ma non funziona e non riesco ad uscirne. Una birra a chi mi aiuta
I'm beautiful and I dance well!
0

#2 User is offline   gdang 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 20-August 11
  • Location:Venice

Posted 31 August 2011 - 06:37 AM

/*	$dataProvider=new CActiveDataProvider('person', array(
		'criteria'=>array(
		'with'=>array('divisions'=>array( 
			'on'=>'divisions.id='.$division['id'], 
			'together'=>true,
			'joinType'=>'RIGHT JOIN', 
			)),
		),
		'pagination'=>array(
			'pageSize'=>20,
		),
		)
	);
*/
	
$rawData=Yii::app()->db->createCommand('SELECT *  FROM tbl_person as p INNER JOIN tbl_person_division as d ON p.id=d.person_id WHERE d.division_id='.$division['id'])->queryAll();
$dataProvider=new CArrayDataProvider($rawData, array(
    'pagination'=>array(
        'pageSize'=>20,
    ),
));

	$this->widget('zii.widgets.grid.CGridView', array(
		'id'=>'griglia',
		'dataProvider'=>$dataProvider,
		'columns'=>array(
			'name',
			'tel1',
			'tel2',
			array(
				'class'=>'CButtonColumn',
				'header'=>'delete',
				'template'=>'{delete}',
				'deleteButtonUrl'=>'Yii::app()->createUrl("corporation/deletePersonRelation",array("id_person"=>$data["person_id"],"id_division"=>$data["division_id"]))',
			),
		),
	));


I'm beautiful and I dance well!
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