migajek
(Migajek)
May 26, 2011, 3:09pm
1
Hi,
let’s assume I have Gallery model which has following relation:
'photos' => array(self::HAS_MANY, 'Photo', 'gallery_id');
now, when displaying single gallery page I’d like to retrieve CActiveDataProvider for $gallery->photos, so I can pass it to CListView.
Is that possible anyhow?
Just an example, customize it as you like:
$photos=Photo::model()->findAll('gallery_id=:gid', array(':gid'=>$data->gallery_id));
if(isset($photos))
{
foreach($photos as $attribute)
{
echo $attribute->your_attribute;
...etc...
}
}
boaz
(Boaz Rymland)
May 27, 2011, 5:34am
3
Sounds like a simple task that is very similar to the one shown in the blog tutorial. there, there are blog post and you want to show the post related comments . Check out how its done here: http://www.yiiframework.com/doc/blog/1.1/en/comment.create
migajek
(Migajek)
May 27, 2011, 11:02am
4
guys, I know the way you showed, it’s obvious and trivial.
What I’m looking for is how to feed CActiveDataProvider with data from “related” field.
What I mean is:
I define relation
I create CActiveDataProvider for that
writing findAll(‘galler_id = :gid’, …) is in fact redefinition of relation, which is against DRY [Don’t Repeat Yourself]