สามารถสร้าง painator ได้แบบง่ายๆ กับ CakePHP

ไฟล์ที่เกี่ยวข้อง
app/controllers/products_controller.php
app/views/products/index.ctp

-------------------------------------------------

products_controller.php
<?php
class ProductsController extends AppController{
var $name='Products';
var $paginate=array('limit'=>5,'page'=>1,'order'=>array('Product.id'=>'desc'));
//limit คือ จำนวน record ต่อหน้า page คือหน้าเริ่มต้น order คือการเรียงลำดับทำเป็น array กรณีที่เรียงมากกว่า 1 column


function index(){
$this->set('products',$this->paginate('Content')); //ทำให้เป็น paginate ตรงนี้ล่ะคับ
}

}

------------------------------------------------

index.ctp

<?php echo $paginator->prev(); ?> // แสดงข้อความ Previus
<?php echo $paginator->numbers(); ?> // แสดง 1 | 2 | 3
<?php echo $paginator->next(); ?> // แสดงข้อความ Next
<?php echo $paginator->counter();?> // แสดง 1 of xx...

<?php foreach $products as $product: ?>
<?php echo $product['Product']['name']."<br";?>
<?php endforeach;?>