Skip to content

Commit

Permalink
add Database method paginationArrayParam()
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanderson committed Aug 17, 2017
1 parent 2ff21cd commit f7c774e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
29 changes: 29 additions & 0 deletions app/vendor/Eco/System/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,35 @@ public function pagination($query, $params = null)
return $r;
}

/**
* Execute query with pagination with array of parameters
*
* @param string $query
* @param mixed $params
* @return \Eco\System\Database\Pagination
* @throws \Exception (LIMIT clause exists in query, or invalid settings)
*/
public function paginationArrayParam($query, $params = null)
{
$p = [];

foreach(func_get_args() as $v)
{
if(is_array($v))
{
foreach($v as $vv)
{
$p[] = $vv;
}
continue;
}

$p[] = $v;
}

return call_user_func_array([$this, 'pagination'], $p);
}

/**
* Execute query
*
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
/**
* Eco version
*/
const ECO_VERSION = '1.3.2';
const ECO_VERSION = '1.3.3';
7 changes: 7 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ else
// warn no rows
}
```

An array of params can be used instead of method params, example:
```php
// SELECT a, b FROM table WHERE x = 1 AND y = 2 LIMIT <page>, <records_per_page>
$p = db()->paginationArrayParam('SELECT a, b FROM table WHERE x = ? AND y = ?', [1, 2]);
```

Pagination settings can be found in the Eco configuration file `app/com/conf/eco.conf.php` under the `database` > `pagination` section, including styles for pagination controls.

> Caching can be used with this method by using a [`Eco\Cache` object](https://github.com/shayanderson/eco/blob/master/docs/cache.md) as the first parameter, example:
Expand Down

0 comments on commit f7c774e

Please sign in to comment.