CActiveDatprovider problem with getData()

Hi,

I have a CActiveDataProvider and i would like to obtain the value of one TITLE,

in my CDetailView

But i don’t know how to do it i tried

$is_serviceRecords->getData()

$is_serviceRecords->getData()->‘TITLE’

but don’t know how to use it

I would like to have this in my view




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

	'data'=>$model,//model show the list of Applications

	'attributes'=>array(

		'APPLICATION_ID',

		'CURRENT_RELEASE_INST',

		array(

			'label'=>'IS Service Name',

			'value'=>$is_serviceRecords->getData()->TITLE //is_serviceRecord is a CactiveDataProvider and should use the IS_SERVICE_ID foreign key to access to it's TITLE

		),

	),

));



Can someone tell me how to?

CActiveDataProvider::getData() returns an array of model objects, not a single object.

But, um, it looks strange to me that you are using a CActiveDataProvider here. We usually use it for CGridView or CListView to display multiple records of data.

I think you could do it much more simple without using CActiveDataProvider.

Could you show us your table schema of ‘Application’ and ‘IsService’? (I don’t know the exact names, but something like those, I guess)

I’m sorry if I’m wrong, but I’m afraid that you are handling a simple BELONGS_TO relation with a very complicated wrong approach.

If you are trying to display multiple records, then CDetailView is the wrong widget.

It is just CActiveDataprovider is the only way i know to get a data from a link with 2 tables,

no, BAckSlider , i just want one value , the value that contains the primary key of the other table linked with the table i want to show

application 1,1-------0,n Is Service

APPLICATION_ID IS_SERVICE_ID

IS_SERVICE_ID

I’m sorry, but I couldn’t understand the relation between “Application” and “IsService” from your description.

Is it "Application" HAS_MANY "IsService"s … 1 to N ?

Or is it "Application" BELONGS_TO "IsService" … N to 1 ?

Could you provide us with the table definitions of them?

Or, please show your code to get $is_serviceRecords. What criteria(condition) are you using to get it?

Is Service HAS_MANY Applications

Applications BELONGS_TO Is Service

I see.

Then something like this?




Application

    application_id ... PK

    current_release_inst

    is_service_id ... FK to IsService

    ...


IsService

    is_service_id ... PK

    title

    ...



Am I right?

If I’m right, then something like this should work.




$this->widget('zii.widgets.CDetailView', array(

    'data' => $model,

    'attributes' => array(

         'APPLICATION_ID',

         'CURRENT_RELEASE_INST',

         array(

              'label' => 'IS Service Name',

              'value' => IsService::model()->findByPk($model->is_service_id)->TITLE,

         ),

     ),

));



Or, by establishing a BELONGS_TO relation named ‘isService’ between Application and IsService:




$this->widget('zii.widgets.CDetailView', array(

    'data' => $model,

    'attributes' => array(

         'APPLICATION_ID',

         'CURRENT_RELEASE_INST',

         array(

              'label' => 'IS Service Name',

              'value' => $model->isService->TITLE,

         ),

     ),

));