2013-11-04 22 views
7

你好我的代碼Yii的findAllByAttributes LIMIT

$allLogins = IpAddressLogin::model()->findAllByAttributes(
    array(
     'user_id' => Yii::app()->user->id, 
     'type' => 'user' 
    ), 
    array(
     'order' => 'date desc', 
     'limit' => '15, 10', 
    )); 

我想從15號記錄10條記錄。但它只給了我最後的15條記錄。
它只解析'限制'中的第一個數字(15)。如何在findAllByAttributes中設置LIMIT 15,10?

+6

你需要'limit'和'offset',在這裏檢查:http://stackoverflow.com/a/12943125/133408 – 2013-11-04 08:49:46

回答

18

你應該使用它的偏移量。請看下面的代碼,它會幫助你設置所需的限制

$allLogins = IpAddressLogin::model()->findAllByAttributes(
array(
    'user_id' => Yii::app()->user->id, 
    'type' => 'user' 
), 
array(
    'order' => 'date desc', 
    'limit' => 10, 
    'offset' => 15 
));