Want to display names instead of id

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

[/i]1745

File.doc

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…

Hello all,

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

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…

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?

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’)); ?>