Yii Framework Forum: [ASK]GII Relasi 2 Tabel One to Many - Yii Framework Forum

Jump to content

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

[ASK]GII Relasi 2 Tabel One to Many Rate Topic: -----

#1 User is offline   rayleigh13 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 03-July 12

Posted 04 July 2012 - 04:23 AM

mau tnya nih,kondisinya saya punya 2 tabel
tabel profil dengan atribut nama,alamat
tabel barang dengan atribut barang beli, barang jual
nah kasusnya relasi one to many jadi misal nama adi alamat jakarta tapi barang beli:kopi,teh,gula barang jual:ikan,daging (1 profil punya banyak barang)
saya maunya di halaman admin cuma ada atribut nama, alamat biar ga ada redudansi baru pas di klik view kluar lg hlaman baru isinya atribut barang jual,barang beli punyanya profil yang di view tadi misal td search nama:adi,trus ketemutrus di klik view(gmbar kca pmbsar sblah knan hsil crud gii) bru kluar tabel crud gii lg yg isinya barang beli, barang jual punyanya profil dengan nama adi
mohon pencerahannya ya
0

#2 User is offline   elixer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 11-July 12
  • Location:Jakarta

Posted 12 July 2012 - 06:23 PM

Pertama-tama ganti viewUrlButton di profil/admin.php:

array(
'class'=>'CButtonColumn',
'viewButtonUrl'=>'array("barang/admindetail","id"=>$data->profilID)',
),

Lalu modify script di model Barang jadi:

public function search($id = NULL)
{

$criteria=new CDbCriteria;
if(isset($id)) {$criteria->compare('contentID',$id);} else {$criteria->compare('contentID',$this->contentID);}

...
}

Lanjut... tambahkan action admindetail di barangController:

public function actionAdmindetail()
{
$model=new Content('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Content']))
$model->attributes=$_GET['Content'];

$this->render('admin2',array(
'model'=>$model,
));
}

Terakhir buat admin2.php yang mirip admin.php tapi tambahkan sedikit script search di options widgetnya:

'dataProvider'=>$model->search($_GET['id']),


Maaf kalau masih ada error. Belum di test soale. Tapi perasaan sih harusnya dah jalan. haha :D
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