sukran
(Skeeran)
May 10, 2014, 12:35pm
1
Hi guys,
i have two tables like
Listing
ID
cat_ID
name
price
etc..
Cat
ID
name
etc..
right i am doing this in view to get the related data for cat_id from table cat … the question is there is simpler and nice way doint it in controller
<?php $cat = Cat:findOne($model->cat_ID);
echo $cat->name; ?>
thanks
JbalTero
(Jbaltero)
May 10, 2014, 2:52pm
2
I don’t understand the problem but I guess this will work fine…
In your controller action,
$model = // I assume you load the 'Listing' model here
$cat = Cat::model()->findByPk( $model->cat_ID );
$this->renderPartial( '_yourView', array(
'cat' => $cat,
// other variables...
));
In your view,
<?php
echo $cat->name;
?>
sukran
(Skeeran)
May 10, 2014, 3:45pm
3
thank you buddy, i thought maybe there is smarter way … you way also superb …
JbalTero:
I don’t understand the problem but I guess this will work fine…
In your controller action,
$model = // I assume you load the 'Listing' model here
$cat = Cat::model()->findByPk( $model->cat_ID );
$this->renderPartial( '_yourView', array(
'cat' => $cat,
// other variables...
));
In your view,
<?php
echo $cat->name;
?>
Why not just add a join to the Listing query?
sukran
(Skeeran)
May 11, 2014, 6:33am
5
maybe you can give a code… i was going through documentation… didn’t get it…