Yii Framework Forum: relational model? - Yii Framework Forum

Jump to content

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

relational model? Cara menampilkan value menggunakan relational model Rate Topic: -----

#1 User is offline   Wiwit Iwan SEP 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-April 11
  • Location:Gresik - Indonesia

Posted 09 April 2011 - 04:49 AM

Sore semua...

saya mempunyai dua table yaitu table TOKO dan table PEMILIK. Field ID di PEMILIK mereference field ID di TOKO dengan relasi one to one. di CGridView model TOKO saya ingin menampilkan field NAMA_DEPAN dari PEMILIK.

di controller:
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(
'pemilik' => array(self::HAS_ONE, 'Pemilik', 'ID'),
);
}

di viewnya:
'columns'=>array(
array(
'name'=>'Nama Pemilik',
'header'=>'Nama Pemilik',
'value'=>'$model->pemilik->NAMA_DEPAN',
),
),

muncul tampilan gridnya tapi valuenya tidak muncul... apa ada yang bisa memberikan pencerahan... Makasih sebelumnya.... -Wiwit Iwan SEP-
0

#2 User is offline   rei 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 329
  • Joined: 10-November 10

Posted 09 April 2011 - 11:39 PM

Udah coba pake $data, gan?

'value'=>'$data->pemilik->NAMA_DEPAN',

Fipick - Find and pick recommendations
0

#3 User is offline   Wiwit Iwan SEP 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-April 11
  • Location:Gresik - Indonesia

Posted 10 April 2011 - 02:47 AM

View Postrei, on 09 April 2011 - 11:39 PM, said:

Udah coba pake $data, gan?

'value'=>'$data->pemilik->NAMA_DEPAN',




udah.. dan hasilnya sama... jumlah recordnya benar.. tp valuenya g muncul... :(
0

#4 User is offline   sbasuki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 14-January 10

Posted 10 April 2011 - 10:05 AM

View PostWiwit Iwan SEP, on 10 April 2011 - 02:47 AM, said:

udah.. dan hasilnya sama... jumlah recordnya benar.. tp valuenya g muncul... :(


Coba name nya diganti :
'columns'=>array(
array(
'name'=>'pemilik.NAMA_DEPAN',
'header'=>'Nama Pemilik',
'value'=>'$data->pemilik->NAMA_DEPAN',
),
),

0

#5 User is offline   Wiwit Iwan SEP 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-April 11
  • Location:Gresik - Indonesia

Posted 10 April 2011 - 10:59 PM

View Postsbasuki, on 10 April 2011 - 10:05 AM, said:

Coba name nya diganti :
'columns'=>array(
array(
'name'=>'pemilik.NAMA_DEPAN',
'header'=>'Nama Pemilik',
'value'=>'$data->pemilik->NAMA_DEPAN',
),
),




sudah... dan saya juga mencoba code sbb:
'columns'=>array(
'pemilik.NAMA_DEPAN'
),

tetap tidak muncul valuenya....
0

#6 User is offline   sbasuki 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 14-January 10

Posted 11 April 2011 - 02:51 AM

View PostWiwit Iwan SEP, on 10 April 2011 - 10:59 PM, said:

sudah... dan saya juga mencoba code sbb:
'columns'=>array(
'pemilik.NAMA_DEPAN'
),

tetap tidak muncul valuenya....


Di config/main.php
coba aktifkan :
				array(
					'class'=>'CWebLogRoute',
				),


liat errornya apa? query yg dijalankan apa oleh Yii,

bisa kasih liat relation masing2 dari model TOKO dan PEMILIK, pastikan dua model tsb didaftarkan relasi yg terkait
0

#7 User is offline   Wiwit Iwan SEP 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-April 11
  • Location:Gresik - Indonesia

Posted 11 April 2011 - 04:45 AM

View Postsbasuki, on 11 April 2011 - 02:51 AM, said:

Di config/main.php
coba aktifkan :
				array(
					'class'=>'CWebLogRoute',
				),


liat errornya apa? query yg dijalankan apa oleh Yii,

bisa kasih liat relation masing2 dari model TOKO dan PEMILIK, pastikan dua model tsb didaftarkan relasi yg terkait


Problem Solved.... :) makasih banyak gan... dengan mengaktifkan CWebLogRoute valuenya langsung muncul...
saya pakai coding:

'columns'=>array(
'pemilik.NAMA_DEPAN'
),
0

#8 User is offline   petra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 218
  • Joined: 20-June 10

Posted 11 April 2011 - 04:46 AM

bisa liat struktur tabel toko sama pemilik gak?
0

#9 User is offline   Wiwit Iwan SEP 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 06-April 11
  • Location:Gresik - Indonesia

Posted 11 April 2011 - 08:56 PM

View Postpetra, on 11 April 2011 - 04:46 AM, said:

bisa liat struktur tabel toko sama pemilik gak?


Struktur Tabel Toko dan Pemilik:

/*=====================================================*/
/* Table: TOKO */
/*===================================================*/
create table TOKO
(
ID numeric(8,0) not null,
KODE_TOKO varchar(10) not null,
NAMA_TOKO varchar(40) not null,
SEARCH_TERM varchar(20),
ALAMAT_JALAN varchar(60) not null,
PROVINSI varchar(25),
DISTRIK varchar(20),
KECAMATAN varchar(20),
KODEPOS varchar(10),
TELEPHONE varchar(30),
TELEPHONE_EXT varchar(10),
FAX varchar(30),
FAX_EXT varchar(10),
MOBILE_PHONE varchar(30),
EMAIL varchar(40),
NAMA_AREA varchar(25),
CREATED_BY varchar(20),
CREATED_DATE varchar(10),
LAST_CHANGED_BY varchar(20),
LAST_CHANGED_DATE varchar(10),
primary key (ID)
);


/*=======================================================*/
/* Table: PEMILIK */
/*=====================================================*/
create table PEMILIK
(
ID numeric(8,0) not null,
KODE_TOKO varchar(10) not null,
NAMA_DEPAN varchar(35),
NAMA_BELAKANG varchar(35),
TLP_PEMILIK varchar(30),
JABATAN varchar(30),
IBU_BAPAK varchar(20),
KODE_AGAMA varchar(2),
AGAMA varchar(25),
TGL_LAHIR varchar(10),
STATUS_KAWIN varchar(35),
CREATED_BY varchar(20),
CREATED_DATE varchar(10),
LAST_CHANGED_BY varchar(20),
LAST_CHANGED_DATE varchar(10),
primary key (ID)
);

alter table PEMILIK add constraint FK_REFERENCE_1 foreign key (ID)
references TOKO (ID) on delete restrict on update restrict;
0

#10 User is offline   petra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 218
  • Joined: 20-June 10

Posted 12 April 2011 - 03:07 AM

oh ternyata udah solve toh,,, beda 1 menit doang postnya :P
0

#11 User is offline   aqge 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 188
  • Joined: 02-September 10
  • Location:Indonesia

Posted 19 April 2011 - 11:18 PM

Jika perlu yang ribet seperti memformat total uang agar tampil CGRIDVIEW

dimodel

public function getFormatedResultBeli(){
  return number_format($this->ReationA->total,2,',','.');
}

public function getFormatedResultJual(){
  return number_format($this->ReationB->total,2,',','.');
}



diGRidView


'columns'=>array(
                'barang',
                array('name'=>'Total Pembelian', 'value'=> '$data->FormatedResultBeli'),
		array('name'=>'Total Penjualan', 'value'=> '$data->gFormatedResultJual'),
		
	),




Semoga tidak salah ...
Best Regard
Tidak ada coding yang salah
Yang ada hanyalah Coding yang lebih baik
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