From f7c774e3ef02de939c3c1b9a2505ee02a79fe56c Mon Sep 17 00:00:00 2001 From: Shay Anderson Date: Thu, 17 Aug 2017 17:15:22 -0400 Subject: [PATCH] add Database method paginationArrayParam() --- app/vendor/Eco/System/Database.php | 29 +++++++++++++++++++++++++++++ app/vendor/Eco/version.php | 2 +- docs/database.md | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/vendor/Eco/System/Database.php b/app/vendor/Eco/System/Database.php index 3f60c66..676db5b 100644 --- a/app/vendor/Eco/System/Database.php +++ b/app/vendor/Eco/System/Database.php @@ -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 * diff --git a/app/vendor/Eco/version.php b/app/vendor/Eco/version.php index 7ec77f3..156f56a 100644 --- a/app/vendor/Eco/version.php +++ b/app/vendor/Eco/version.php @@ -11,4 +11,4 @@ /** * Eco version */ -const ECO_VERSION = '1.3.2'; \ No newline at end of file +const ECO_VERSION = '1.3.3'; \ No newline at end of file diff --git a/docs/database.md b/docs/database.md index 8834c76..8bb17e9 100644 --- a/docs/database.md +++ b/docs/database.md @@ -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 , +$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: