Cpagination with Relation


I would like to create pagination on my page, I’m using a CActive Relation in my model

'events' => array(self::HAS_MANY, 'Events', 'marker_id'),

so in my view I'm essentially doing 

foreach($model->events as $event) {

echo $event->name;


I would like to do a pagination on this. Is there a way to do it within the relation?

Thank You

Try this it worked very well for me.

I’m trying to do it off a relation, not a new Model::model()->findBy pretty sure what you gave me doesn’t work.

I havent had any luck with this.

I had the same problem as well. But I got this solved through using CListView and a CArrayDataProvider.



$dataProvider = new CArrayDataProvider($rawData = $model->comments);

$this->widget('zii.widgets.CListView', array



    'itemView'=>'_comment',   // refers to the partial view named '_comment'


I also added a comement view file


<div class="comment">

    <div class="author">

        <?php echo CHtml::encode($data->logger); ?>


    <div class="time">

        <?php echo CHtml::encode(date('j F Y \a\t h:i a',$data->created_at)); ?>


    <div class="content">

        <?php echo CHtml::encode($data->content); ?>



CListView is highly customisable and you could use it to do just about everything you want.

Please see topic:

Pagination with HAS_MANY, BELONGS_TO