Yii Framework Forum: Want to display names instead of id - Yii Framework Forum

Jump to content

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

Want to display names instead of id

#1 User is offline   Aruna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 13-June 11

Posted 16 June 2011 - 12:51 AM

Happy Day.. to All

I was Very new to Yii framework, I just started to learn and it was very interesting, and with reference of Agile book I have started a sample project, I don’t know how to display names instead of id in manage I can change in view but not in manage ., Please any one help me.
Attached File  File.doc (124.5K)
Number of downloads: 41
0

#2 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 16 June 2011 - 01:55 AM

The view and manage view have the same controller/model (ProjectInfo if I look at the screenshots) right?

Then it normally should work cause you are using in both views the ProjectInfo Model and Controller. so the important part, the relations, are for both views the same.

What have you tried to display the name instead of the id?

Post your relations of the involved models and relevant parts of the views here so we could better understand what's your problem.
0

#3 User is offline   Aruna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 13-June 11

Posted 16 June 2011 - 02:10 AM

View Postkokomo, on 16 June 2011 - 01:55 AM, said:

The view and manage view have the same controller/model (ProjectInfo if I look at the screenshots) right?

Then it normally should work cause you are using in both views the ProjectInfo Model and Controller. so the important part, the relations, are for both views the same.

What have you tried to display the name instead of the id?

Post your relations of the involved models and relevant parts of the views here so we could better understand what's your problem.




Hi..

Thanks for replying ., i have attached the related files ., can you plz view the file and tell me what mistake i have done..

thanks..

Attached File(s)


0

#4 User is offline   Aruna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 13-June 11

Posted 20 June 2011 - 06:08 AM

Hello all,


For the past one week i was trying to solve this.. but nothing works..Plz any one help me to solve this..
0

#5 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 20 June 2011 - 11:17 PM

It does not appear that you attached the view file for the "manage" view you are struggling with.

However, assuming you are using passing a CActiveDataProvider to a CGridView for display, you can specify the columns attribute to display different values. This is similar to what you have done in the specification of the attributes property for the CDetailView.

So, in your manage view....

$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$dataProvider,
	'columns'=>array(
    	array(        	
        	'name'=>'project_status_id',
        	'value'=>'$data->projectStatus->project_status_name',
    	),
...


You'll have to do more work to get the searching on these values to behave as expected, but this might get you going in the right direction for the display of the data.
0

#6 User is offline   Aruna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 13-June 11

Posted 21 June 2011 - 02:39 AM

View Postjefftulsa, on 20 June 2011 - 11:17 PM, said:

It does not appear that you attached the view file for the "manage" view you are struggling with.

However, assuming you are using passing a CActiveDataProvider to a CGridView for display, you can specify the columns attribute to display different values. This is similar to what you have done in the specification of the attributes property for the CDetailView.

So, in your manage view....

$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$dataProvider,
	'columns'=>array(
    	array(        	
        	'name'=>'project_status_id',
        	'value'=>'$data->projectStatus->project_status_name',
    	),
...


You'll have to do more work to get the searching on these values to behave as expected, but this might get you going in the right direction for the display of the data.



Thank You .. So Much.. It worked..
0

#7 User is offline   michael so 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 15-August 13

Posted 23 August 2013 - 04:09 AM

tried it but doesnt work for me.

here is my view.php

<?php $this->widget('bootstrap.widgets.TbDetailView',array(
	'data'=>$model,
	'attributes'=>array(
		'id_day',
        array(
            'name'=>'mon',
            'value'=>$model->monday->name,
        ),
        array(
            'name'=>'tue',
            'value'=>$model->tuesday->name,
        ),



and here is my relations


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(
            'monday'=>array(self::BELONGS_TO,'Shift','mon'),
            'tuesday'=>array(self::BELONGS_TO,'Shift','tue'),
            'wednesday'=>array(self::BELONGS_TO,'Shift','wed'),
            'thursday'=>array(self::BELONGS_TO,'Shift','thurs'),
            'friday'=>array(self::BELONGS_TO,'Shift','fri'),
            'saturday'=>array(self::BELONGS_TO,'Shift','sat'),
            'sunday'=>array(self::BELONGS_TO,'Shift','sun'),
		);
	}



then here is my admin.php

<?php $this->widget('bootstrap.widgets.TbGridView',array(
	'id'=>'day-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'id_day',
		array(
            'name'=>'monday',
            'value'=>'$data->monday->name',
        ),
		'tue',
		'wed',
		'thurs',
		'fri',
		/*
		'sat',
		'sun',
		*/
		array(
			'class'=>'bootstrap.widgets.TbButtonColumn',
		),
	),
)); ?>



it says Trying to get property of non-object

can you help me with this?
0

#8 User is offline   parkerfrank 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 02-October 12

Posted 07 November 2013 - 06:02 AM

I think you can simply use this in one line.
// format models resulting using listData
<?php echo $form->dropdownlist($model,'user_id', CHtml::listData(User::model()->findAll(),'id', 'name')); ?>
0

#9 Guest_Ann D. Guerrero_*

  • Group: Guests

Posted 06 February 2014 - 06:45 AM

Welcome in agile development, Glad to know you start your sample project. This is a good strategy to learn and practice. Which book of agile you are following ???
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