In this task, we will be creating a simple search interface for searching the existing customer records by name using the following steps:
We will need to create a search function in the
CustomerRepository
model (MyMobileService\src\MyCompany\Model\CustomerRepository.php
):public function getSearch($query) { $where = new \Zend\Db\Sql\Where(); $where->like('name', "%$query%"); return $this->customerTable->select($where)->toArray(); }
Add a new action in
RpcController
(MyMobileService\src\MyCompany\Controller\RpcController.php
); this will handle the web service request:public function getSearchCustomersAction ($query) { $cr = new CustomerRepository(); return $cr->getSearch($query); }
In the gateway editor, create a new RPC service; set the following options:
URL:
/search
Method:
GET
Request Parameters(Add): Name –
query
; Source –Route
Handler Method:
MyCompany\Controller...