A <-- B --> C
id_A (PK) id_B (PK) id_C (PK)
id_A (FK) attribut1
id_C (FK)
bagaimana mengambil nilai atribut1 model C dari model A?
Posted 03 August 2009 - 08:29 AM
A <-- B --> C
id_A (PK) id_B (PK) id_C (PK)
id_A (FK) attribut1
id_C (FK)
Posted 03 August 2009 - 10:11 AM
...
public function relations()
{
return array(
'namaRelasiKeB'=>array(self::HAS_MANY, 'B', 'id_A'),
);
}
...
...
private $_model;
...
//misal attribut1 C ingin dikeluarkan pada actionShow
public function actionShow()
{
$a = $this->loadA();
$this->render(
'show',
array(
'model'=>$a,
'bs'=>$a->namaRelasiKeB,
)
);
}
...
public function loadA($id=null)
{
if($this->_model===null)
{
if($id!==null || isset($_GET['id']))
$this->_model=A::model()->findbyPk($id!==null ? $id : $_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
...
<?php IF (!empty($bs)): ?>
<?php foreach ($bs as $ B) : ?>
Attribut1 = <?php echo C::model()->findByAttributes(array('id_C'=>$b->id_C))->attribut1;?></td>
<?php endforeach;?>
<?php else:?>
Tidak ada data yang berelasi.
<?php endif;?>
Posted 04 August 2009 - 11:04 PM
.....
public funtion relations(){
return array (
'namaRelasiKeC'=>array(self::MANY_MANY, 'C', 'B(A_id, C_id)'),
);
}
public function actionShow()
{
$a = $this->loadA();
$this->render(
'show',
array(
'model'=>$a,
)
);
}
...
public function loadA($id=null)
{
if($this->_model===null)
{
if($id!==null || isset($_GET['id']))
$this->_model=A::model()->with("namaRelasiKeC")->findbyPk($id!==null ? $id : $_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
<?php IF (!empty($model->namaRelasiKeC)): ?>
<?php foreach ($model->namaRelasiKeC as $C) : ?>
Attribut1 = <?php echo $C->attribut1;?>
<?php endforeach;?>
<?php else:?>
Tidak ada data yang berelasi.
<?php endif;?>
Posted 08 September 2009 - 03:38 AM
Posted 25 December 2009 - 08:14 PM
Gygie, on 08 September 2009 - 03:38 AM, said:
<?php
class B extends CActiveRecord
{
...
public function relations()
{
return array(
'relKeA'=>array(
self::BELONGS_TO,'A','fKeyA',
'joinType'=>'INNER JOIN',
),
'relKeC'=>array(
self::BELONGS_TO,'C','fKeyC',
'joinType'=>'INNER JOIN',
),
);
}
...
}
?>
<?php
class BController extends CController
{
...
public function actionShow()
{
//panggil model B dari behavior loadB() yang sudah ada dalam controller
$modelB = $this->loadB();
//atau bisa juga dengan langsung memanggil modelnya.
//$modelB = B::model()->findAll($category);
//render view Show
$this->render('show',array('dataModelB'=>$modelB));
}
...
}
?>
...
<?php IF (!empty($dataModelB)): ?>
<?php foreach ($dataModelB as $B) : ?>
id_A Tabel A = <?php echo $b->relKeA->id_A;?>
Attribut1 Tabel C = <?php echo $b->relKeC->attribut1;?>
<?php endforeach;?>
<?php else:?>
Tidak ada data yang berelasi.
<?php endif;?>
...
Posted 17 May 2010 - 10:36 PM
Posted 06 June 2010 - 03:32 AM
...
<?php
echo $form->dropDownList(
$news,
'category_id',
news_category::model()->findAll() //ambil data langsung dari tabel
);
?>
...return array( 'kategori'=>array(self::BELONGS_TO,'news_category','category_id'), );
<?php echo $news->kategori->category;?>
Posted 12 June 2010 - 06:16 AM
nasrul, on 06 June 2010 - 03:32 AM, said:
...
<?php
echo $form->dropDownList(
$news,
'category_id',
news_category::model()->findAll() //ambil data langsung dari tabel
);
?>
...return array( 'kategori'=>array(self::BELONGS_TO,'news_category','category_id'), );
<?php echo $news->kategori->category;?>
Posted 18 June 2010 - 01:17 AM
__agus, on 12 June 2010 - 06:16 AM, said:
Posted 24 June 2010 - 01:15 PM
.....
public funtion relations(){
return array (
'namaRelasiKeC'=>array(self::MANY_MANY, 'C', 'B(A_id, C_id)'),
);
}
Posted 25 June 2010 - 04:42 AM
junxiong, on 24 June 2010 - 01:15 PM, said:
.....
public funtion relations(){
return array (
'namaRelasiKeC'=>array(self::MANY_MANY, 'C', 'B(A_id, C_id)'),
);
}
A <-- B --> C
id_A (PK) id_B (PK) id_C (PK)
id_A (FK) attribut1
id_C (FK)
Posted 28 June 2010 - 10:17 PM
Posted 01 July 2010 - 03:59 AM
bhoo-day, on 18 June 2010 - 01:17 AM, said:
..
<body>
<div id="header">Yii Website</div>
<div id="main-menu">Menu-menu</div>
<div id="sidebar">
blokym akan ditaruh disini..
</div>
<div id="content"><?php echo $content; ?></div>
<div id="footer">Copyright..</div>
</body>
..
Posted 30 August 2010 - 01:09 AM
nasrul, on 05 August 2009 - 02:46 AM, said:
A <-- B --> C --> D
id_A (PK) id_B (PK) id_C (PK) id_D (PK)
id_A (FK) attribut1 Atribut2
id_C (FK) id_D
Posted 30 August 2010 - 08:00 AM
ariefpriyadi, on 30 August 2010 - 01:09 AM, said:
A <-- B --> C --> D
id_A (PK) id_B (PK) id_C (PK) id_D (PK)
id_A (FK) attribut1 Atribut2
id_C (FK) id_D
<?php
..
public funtion relations(){
return array (
'namaRelasiKeC'=>array(self::MANY_MANY, 'C', 'B(id_A, id_C)'),
);
}
...
?><?php
...
public funtion relations(){
return array (
'namaRelasiKeD'=>array(self::BELONGS_TO, 'D', 'id_D'),
);
}
...
?><?php
foreach (A::model()->findAll() as $dataA){
foreach ($dataA->namaRelasiKeC->namaRelasiKeD as $dataD){
echo $dataD->Atribut2;
}
}
?>Quote
$this->render('view',array('dataA'=>A::model()->findAll()));
Posted 01 September 2010 - 04:01 AM
nasrul, on 30 August 2010 - 08:00 AM, said:
<?php
..
public funtion relations(){
return array (
'namaRelasiKeC'=>array(self::MANY_MANY, 'C', 'B(id_A, id_C)'),
);
}
...
?><?php
...
public funtion relations(){
return array (
'namaRelasiKeD'=>array(self::BELONGS_TO, 'D', 'id_D'),
);
}
...
?><?php
foreach (A::model()->findAll() as $dataA){
foreach ($dataA->namaRelasiKeC->namaRelasiKeD as $dataD){
echo $dataD->Atribut2;
}
}
?>
....
foreach ($dataA->namaRelasiKeC->namaRelasiKeD as $dataD){
echo $dataD->Atribut2;
...
Posted 28 October 2010 - 09:35 PM
nasrul, on 25 December 2009 - 08:14 PM, said:
<?php
class B extends CActiveRecord
{
...
public function relations()
{
return array(
'relKeA'=>array(
self::BELONGS_TO,'A','fKeyA',
'joinType'=>'INNER JOIN',
),
'relKeC'=>array(
self::BELONGS_TO,'C','fKeyC',
'joinType'=>'INNER JOIN',
),
);
}
...
}
?>
<?php
class BController extends CController
{
...
public function actionShow()
{
//panggil model B dari behavior loadB() yang sudah ada dalam controller
$modelB = $this->loadB();
//atau bisa juga dengan langsung memanggil modelnya.
//$modelB = B::model()->findAll($category);
//render view Show
$this->render('show',array('dataModelB'=>$modelB));
}
...
}
?>
...
<?php IF (!empty($dataModelB)): ?>
<?php foreach ($dataModelB as $B) : ?>
id_A Tabel A = <?php echo $b->relKeA->id_A;?>
Attribut1 Tabel C = <?php echo $b->relKeC->attribut1;?>
<?php endforeach;?>
<?php else:?>
Tidak ada data yang berelasi.
<?php endif;?>
...