I plan to implement an RPC Service in API Tools environment that uses a number of entities.
Following function returns the number (
$offset) of records from (starting record).
public function findCustomerOrders($customerId,$offset,$from)
public function listCustomerOrdersAction()
//get customer Id
$customerId = (int)$this->params()->fromRoute('customer_id',-1);
$offset = (int)$this->params()->fromRoute('offset',-1);
$from = (int)$this->params()->fromRoute('from',-1);
$orders = $this->listCustomerOrdersService->findCustomerOrders($customerId,$offset,$from);
The controller function here shows the output as follows:
In the above code when I un-comment the var_dump statement it does show lengthy output(the browser keeps on fetching data forever).
My aim is to return the records, what should be my return type and what do I return. Or do I have to use HAL as shown in the following link
Thanks in advance.
For an RPC Service you have to return an instance of
class YouController extends AbstractActionController
public function yourAction()
// fetch your data here
$data = ;
return new ViewModel([
'payload' => $data,
The data you want to return must be named under the key
payload. The payload holds the data you want to return in HAL format. You can chose any other key for simple JSON format.
The Laminas API Tools are well documented. A working example how to return the HAL format from a RPC service, you can see here.
I have used the above but I am still getting the empty record though it is in HAL format:
Where could I be missing?
Did you check the values of the following variables:
$from? I suggest using a debugging tool like XDebug or a simple
var_dump($customerId, $offset, $from). What is the content or even better the type of
$orders? You can check that with
$orders orders is a result collection you could check, if it contains a rowset with
With XDebug you could easily check the type and the content with a simple stoppoint.
To keep it short: Check the values of your variables and the doctrine result.