S
S
skijaev2014-03-19 14:08:44
Yii
skijaev, 2014-03-19 14:08:44

How to set limit and offset in CDbCriteria with with in Yii?

I have categories and articles, the article has a relation 'Irelations'=>array(self::HAS_MANY, 'VPRelation', 'post_id'),
I get all articles from the category

$Criteria = new CDbCriteria(array(
                                            'with' => array(
                                                'Irelations' => array(
                                                    'select' => '*',
                                                    'joinType' => 'INNER JOIN',
                                                    'condition' => 'Irelations.category_id=' . $Category->id,
                                                ),
                                            ),
                                            'order' => 't.publicated DESC',
                                            'condition' => 't.status='.VP::StatusActive.' or t.status = '.VP::StatusActivePending,
                                 ));
                                $Allnodes = VPost::model()->findAll($Criteria );

How to set a limit and an offset in this case, do I need it to implement my pagination (not a widget)?
And another stupid question, when I need to know the total number of records in a category, I make a request
$countAllnodes = count(VPost::model()->findAll($Criteria ));
at the same time all received records are loaded into memory? Or is the quantity calculated only from the meta?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TekVanDo, 2014-03-19
@TekVanDo

limit and offset touch

$criteria->limit = '20';
// смещение
$criteria->offset = '3';

CDbCriteria (methods)
An example of using CDbCriteria
and in general why write a bicycle and not use CPagination

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question