Skip to content

Commit 2148713

Browse files
committed
Merge pull request #353 from avbdr/master
fixes
2 parents e4746f8 + 246e275 commit 2148713

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

MysqliDb.php

+3
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,9 @@ protected function replacePlaceHolders ($str, $vals) {
13411341
$i = 1;
13421342
$newStr = "";
13431343

1344+
if (empty ($vals))
1345+
return $str;
1346+
13441347
while ($pos = strpos ($str, "?")) {
13451348
$val = $vals[$i++];
13461349
if (is_object ($val))

dbObject.md

+10
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ Object could be easily converted to a json string or an array.
285285
$userArray = $user->toArray();
286286
```
287287

288+
###Pagination
289+
Use paginate() instead of get() to fetch paginated result
290+
```php
291+
$page = 1;
292+
// set page limit to 2 results per page. 20 by default
293+
product::$pageLimit = 2;
294+
$products = product::arraybuilder()->paginate($page);
295+
echo "showing $page out of " . product::$totalPages;
296+
297+
```
288298
###Examples
289299

290300
Please look for a use examples in <a href='tests/dbObjectTests.php'>tests file</a> and test models inside the <a href='tests/models/'>test models</a> directory

dbObject.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ class dbObject {
8080
*
8181
* @var int
8282
*/
83-
public $pageLimit = 20;
83+
public static $pageLimit = 20;
8484
/**
8585
* Variable that holds total pages count of last paginate() query
8686
*
8787
* @var int
8888
*/
89-
public $totalPages = 0;
89+
public static $totalPages = 0;
9090
/**
9191
* An array that holds insert/update/select errors
9292
*
@@ -427,10 +427,10 @@ protected function count () {
427427
* @return array
428428
*/
429429
private function paginate ($page, $fields = null) {
430-
$offset = $this->pageLimit * ($page - 1);
430+
$offset = self::$pageLimit * ($page - 1);
431431
$this->db->withTotalCount();
432-
$results = $this->get (Array ($this->pageLimit, $offset), $fields);
433-
$this->totalPages = round ($this->db->totalCount / $this->pageLimit);
432+
$results = $this->get (Array ($offset, self::$pageLimit), $fields);
433+
self::$totalPages = round ($this->db->totalCount / self::$pageLimit);
434434

435435
return $results;
436436
}

0 commit comments

Comments
 (0)