i really need a hand on this...please

Hi again…

I don’t know what else to do…i’m trying to present the result of joining two or more tables. To present it, i’m using CGridView. I could spent A LOT of time showing every f***ing way i tried to make this work but, instead, i will show you the code and ask for some examples of you…

the view…




<div class="message zone">

	<?php

		if($message!=null)

			echo $message;

	?>

</div>




<div class="title">

	<?php echo $community->name;?>

</div>


<br/>


<?php CHtml::image($community->photo,'',array('width'=>100, 'height'=>100));?>


<br/>


<div class="description">

	<?php 

	$htmlOptions = array();

	if(Yii::app()->authManager->checkAccess('Coordinator|'. $community->id, Yii::app()->user->id))

		$htmlOptions['disabled'] = 'disabled';

	echo CHtml::activeTextArea($community,'description',$htmlOptions);

	?>

</div>


<br/>


<div class="button">

	<?php 

	if(CommunityController::currentUserHasAccess('OpenClose Community',Yii::app()->user,$community->id)){

		if($community->is_open){

			/*

			 * Link to close the community

			 */

			echo CHtml::link('fechar a comunidade', array('/community/close&community_id='. $community->id));

		}else{

			/*

			 * Link to open the community

			 */

			echo CHtml::link('abrir a comunidade', array('/community/open&community_id='. $community->id));

		}

	}

	?>

<br/>


<div>

	<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'community-grid',

	'dataProvider'=>$users->searchPerCommunity($community->id),

	'filter'=>$users,

	'columns'=>array(

		//'id',

		'name',

		//'description',

		//'founder_id',

//		array(          

//            'name'=>'community id',

//            'value'=>'$data->user_rights->community_id',

//        ),

		/*

		'is_open',

		'can_publish',

		

		'is_permanent',

		'is_formal',

		'photo',

		'member_filter',

		*/

//		array(

//			'class'=>'CButtonColumn',

//		),

	),

)); ?>

</div>



the model…




<?php


class User extends CActiveRecord

{

	/**

	 * The followings are the available columns in table 'user':

	 * @var integer $id

	 * @var integer $clip_id

	 * @var string $username

	 * @var string $password

	 * @var string $name

	 * @var string $photo

	 * @var integer $location

	 * @var string $birthday

	 * @var string $sex

	 */


	/**

	 * Returns the static model of the specified AR class.

	 * @return User the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'user';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('username, password', 'required'),

			array('clip_id, location', 'numerical', 'integerOnly'=>true),

			array('username', 'length', 'max'=>45),

			array('password', 'length', 'max'=>40),

			array('name, photo', 'length', 'max'=>100),

			array('sex', 'length', 'max'=>1),

			array('birthday', 'safe'),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, clip_id, username, password, name, photo, location, birthday, sex', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	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(

			'user_has_communitys' => array(self::MANY_MANY, 'Community', 'community_user(user_id,community_id)'),

			'invititations_from_communities' => array(self::MANY_MANY, 'Community', 'invitation(user_id, community_id)'),

			'user_rights' => array(self::HAS_MANY, 'CommunityUser', 'user_id'),

			'emails' => array(self::HAS_MANY, 'Email', 'user_id'),

			'external_user' => array(self::HAS_ONE, 'ExternalUser', 'id'),

			'clip' => array(self::BELONGS_TO, 'InternosCliptable', 'clip_id'),

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'Id',

			'clip_id' => 'CLIP',

			'username' => 'Username',

			'password' => 'Password',

			'name' => 'Name',

			'photo' => 'Photo',

			'location' => 'Location',

			'birthday' => 'Birthday',

			'sex' => 'Sex',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributcommunity_ides that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);


		$criteria->compare('clip_id',$this->clip_id);


		$criteria->compare('username',$this->username,true);


		$criteria->compare('password',$this->password,true);


		$criteria->compare('name',$this->name,true);


		$criteria->compare('photo',$this->photo,true);


		$criteria->compare('location',$this->location);


		$criteria->compare('birthday',$this->birthday,true);


		$criteria->compare('sex',$this->sex,true);


		return new CActiveDataProvider('User', array(

			'criteria'=>$criteria,

		));

	}

	

	public function searchPerCommunity($community_id)

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

		

		$criteria->select = 'community_user.user_id';

		

		//$criteria->condition = 'community_user.community_id = '. $community_id;

		

		//$criteria->select = 'community_user.community_id';

		

		$criteria->join = 'JOIN community_user ON community_user.user_id = id';


		$criteria->compare('id',$this->id);


		$criteria->compare('username',$this->username,true);


		$criteria->compare('name',$this->name,true);


		$criteria->compare('photo',$this->photo,true);


		$criteria->compare('location',$this->location);


		$criteria->compare('birthday',$this->birthday,true);


		$criteria->compare('sex',$this->sex,true);

		

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


		return new CActiveDataProvider('User', array(

			'criteria'=>$criteria,

		));

	}

}



the model for community_user…




<?php


class CommunityUser extends CActiveRecord

{

	/**

	 * The followings are the available columns in table 'community_user':

	 * @var integer $user_id

	 * @var integer $community_id

	 * @var integer $is_suspended

	 * @var integer $can_invite

	 * @var integer $change_state

	 * @var integer $edit_templates

	 * @var integer $deactivate_community

	 * @var integer $manage_users

	 */


	/**

	 * Returns the static model of the specified AR class.

	 * @return CommunityUser the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'community_user';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('user_id, community_id', 'required'),

			array('user_id, community_id, is_suspended, can_invite, change_state, edit_templates, deactivate_community, manage_users', 'numerical', 'integerOnly'=>true),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('user_id, community_id, is_suspended, can_invite, change_state, edit_templates, deactivate_community, manage_users', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	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(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'user_id' => 'User',

			'community_id' => 'Community',

			'is_suspended' => 'Is Suspended',

			'can_invite' => 'Can Invite',

			'change_state' => 'Change State',

			'edit_templates' => 'Edit Templates',

			'deactivate_community' => 'Deactivate Community',

			'manage_users' => 'Manage Users',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('user_id',$this->user_id);


		$criteria->compare('community_id',$this->community_id);


		$criteria->compare('is_suspended',$this->is_suspended);


		$criteria->compare('can_invite',$this->can_invite);


		$criteria->compare('change_state',$this->change_state);


		$criteria->compare('edit_templates',$this->edit_templates);


		$criteria->compare('deactivate_community',$this->deactivate_community);


		$criteria->compare('manage_users',$this->manage_users);


		return new CActiveDataProvider('CommunityUser', array(

			'criteria'=>$criteria,

		));

	}

}



What i JUST want is to have a way of putting the fields of other tables in the grid view of the view. For example, listing the user rights’ columns per user, in the view. One thing: the view file i showed you is the one that shows the users of a community. So, i want to list all the users in that community…

I could show you the ways i tried to make this work but, after that, you wouldnt have the will to read that “book” :-[

so…can you help me? I’m really desperate about this…

Mmm no real idea. :unsure:

From first sight, Something bothers me: it’s that relations are set in User model only, not in CommunityUser. I’ve always set both sides.

sorry Pal, night is starting for me in Argentina. M’ going to sleep.

Didn’t read everything, but from a quick look:


// 'value'=>'$data->user_rights->community_id',



this can’t work, since user_rights is an array of CommunityUser records. Maybe that’s the reason for all your troubles?

thanks for the help but i abandone the CGridView solution…it’s way too limitated or complicated to do…