-
-
Save hurlatunde/a747e9e7bca484f1c4bbcc463e6123d2 to your computer and use it in GitHub Desktop.
CakePHP sample with custom query and pagination.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php pr($list); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends AppModel | |
{ | |
public function paginate($conditions, $fields, $order, $limit, $page=1, $recursive=null, $extra=array()) | |
{ | |
$row_start = ($page-1) * $limit; | |
return $this->query(" | |
SELECT User.*, SUM(Cutis.length) | |
FROM User | |
LEFT JOIN Cutis ON User.id=Cutis.user_id | |
GROUP BY User.id | |
LIMIT $row_start, $limit | |
"); | |
} | |
public function paginateCount($conditions=0, $recursive=0, $extra=array()) | |
{ | |
$r = $this->query(" | |
SELECT COUNT(User.id) FROM User | |
"); | |
return $r['COUNT(User.id']; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserController extends AppController | |
{ | |
var $uses = array('User'); | |
var $components = array('Paginator'); | |
function index() | |
{ | |
$this->Paginator->paginate = array( | |
'limit' => 25 | |
); | |
$this->set('list', $this->Paginator->paginate()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment