Yii Framework Forum: Can't Show Owner And Requester Name In View.php - Yii Framework Forum

Jump to content

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

Can't Show Owner And Requester Name In View.php Can't show owner and requester name in view.php

#1 User is offline   agus kianto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-January 13

Posted 20 January 2013 - 09:33 PM

Hi everyone, I got stuck in this one case.

I try to show username based on id of the user, so I set relation in issue 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(
'requester' => array(self::BELONGS_TO, 'Issue', 'requester_id'),
'owner' => array(self::BELONGS_TO, 'Issue', 'owner_id'),
'project' => array(self::BELONGS_TO, 'Project', 'project_id')
);
}

and, I put relation in project 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(
'issues' => array(self::HAS_MANY, 'Issue', 'project_id'),
'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id, user_id)')
);
}

But, I try to see the output of the view.php of issue model can't show the username although I have put (see attachment)

<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'name',
'description',
array(
'name'=>'type_id',
'value'=>CHtml::encode($model->getTypeText()),
),
array(
'name'=>'status_id',
'value'=>CHtml::encode($model->getStatusText()),
),
array(
'name'=>'owner_id',
'value'=>CHtml::encode($model->owner->username), //doesn't show up
),
array(
'name'=>'requester_id',
'value'=>CHtml::encode($model->requester->username), //doesn't show up
)
),
));

Attached File(s)


0

#2 User is offline   agus kianto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-January 13

Posted 20 January 2013 - 09:34 PM

Any idea?
0

#3 User is offline   Joemaxwell 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 13-February 13
  • Location:Fiji Via Melbourne

Posted 03 April 2013 - 05:59 PM

Same with me any idea people thanks.
0

#4 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 03 April 2013 - 07:48 PM

I think your requester and owner relations in Issue are pointing to the wrong model.

public function relations()
{
	return array(
		'requester' => array(self::BELONGS_TO, 'User', 'requester_id'), // Not Issue
		'owner' => array(self::BELONGS_TO, 'User', 'owner_id'), // Not Issue
		'project' => array(self::BELONGS_TO, 'Project', 'project_id')
	);
}


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