laminas-api-tools / api-tools

Laminas API Tools module for Laminas
https://api-tools.getlaminas.org/documentation
BSD 3-Clause "New" or "Revised" License
37 stars 19 forks source link

How to implement pagination for fetch all - collection #5

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

Hi, I am using apigility [Rest API]. I want to implement pagination for my collection services [Fetch all()]. I din't use doctorine, ORM or any mapper classes etc... I just use cutom queries which will output data as array.

My data retrieving code from DB

use Zend\Db\Sql\Select; use Zend\Db\Sql\Sql;

$sql = new Sql ( $this->db ); // Db adapter details $select = $sql->select (); $select->from ( 'user' ); // My table name

$select->columns ( array ( 'userName'=> 'user_name', // Table fields 'userGuid' => user_guid // Table fields ) );

$select->where ( array ( 'deleted' => 0 // where condition ) );

$stmt = $sql->prepareStatementForSqlObject ( $select ); // To prepare statement $resultData = $stmt->execute (); // To execute statment

$result = iterator_to_array ( $resultSet ); return $result; // This will return collection data as array

How to implement pagination concept for this code?

Thank in advance!!


Originally posted by @sarathbabuSwamynathan at https://github.com/zfcampus/zf-apigility/issues/190

weierophinney commented 4 years ago

Did you get it to work?


Originally posted by @roheim at https://github.com/zfcampus/zf-apigility/issues/190#issuecomment-476617340

weierophinney commented 4 years ago

https://blog.tomhanderson.com/2014/10/returning-elasticsearch-hal-collection.html


Originally posted by @TomHAnderson at https://github.com/zfcampus/zf-apigility/issues/190#issuecomment-476726646

weierophinney commented 4 years ago

Thanks @TomHAnderson. Do you have for REST too?


Originally posted by @roheim at https://github.com/zfcampus/zf-apigility/issues/190#issuecomment-477176872

weierophinney commented 4 years ago

I don't use Zend\Db. If you have questions about Doctrine in Apigility I can help you.

Tom

On Wed, Mar 27, 2019 at 8:19 AM David Roheim notifications@github.com wrote:

Thanks @TomHAnderson https://github.com/TomHAnderson. Do you have for REST too?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zfcampus/zf-apigility/issues/190#issuecomment-477176872, or mute the thread https://github.com/notifications/unsubscribe-auth/AAeJYGth968uJNkPiSBmMl7an3GtgDvmks5va33tgaJpZM4NrLMD .


Originally posted by @TomHAnderson at https://github.com/zfcampus/zf-apigility/issues/190#issuecomment-477247062