Yii Framework Forum: Cpagination with Relation - Yii Framework Forum

Jump to content

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

Cpagination with Relation Rate Topic: -----

#1 User is offline   Chief 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 27-September 11

Posted 04 March 2012 - 03:35 AM

Hi,

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
0

#2 User is offline   alexFidelis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 17-November 11

Posted 04 March 2012 - 08:27 AM

Try this it worked very well for me.
0

#3 User is offline   Chief 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 27-September 11

Posted 04 March 2012 - 12:49 PM

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

#4 User is offline   Chief 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 27-September 11

Posted 04 March 2012 - 08:21 PM

I havent had any luck with this.
0

#5 User is offline   Madi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 06-March 12
  • Location:Germany

Posted 11 July 2012 - 01:55 AM

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

/app/views/service/view.php
<?php
$dataProvider = new CArrayDataProvider($rawData = $model->comments);

$this->widget('zii.widgets.CListView', array
(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_comment',   // refers to the partial view named '_comment'
));


I also added a comement view file

/app/views/service/_comment.php
<div class="comment">
    <div class="author">
        <?php echo CHtml::encode($data->logger); ?>
    </div>
    <div class="time">
        <?php echo CHtml::encode(date('j F Y \a\t h:i a',$data->created_at)); ?>
    </div>
    <div class="content">
        <?php echo CHtml::encode($data->content); ?>
    </div>
</div>


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
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