Thứ Năm, 24 tháng 4, 2014

Zend Server Gateway [Building Mobile Applications]

Zend Server Gateway is a lightweighweb services gateway based on Zend Framework 2, which allowfor the mapping of web service routes tvarious controller/actions of the web services. Zend Server Gateway is responsiblefor authentication, validation, filtering, and routing for RPC and RESTful APIs used in CCM projects.

The routing configurations are mapped intconfig/gateway.xml; the routes and configurations can be managed using the gateway editor interface provided in Zend Studio.

In this task, we will be creating a simple search interface for searching the existing customer records by name using the following steps:

1.       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();
}

2.       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);
}

3.       In the gateway editor, create a new RPC service; set the following options:
        URL/search
        MethodGET
        RequesParameters(Add)Name – querySource – Route
        Handler MethodMyCompany\Controller\RpcController::getSear chCustomersAction

4.       You can test the RPC service by right-clicking on the service and choosing Test Service. On the right-hand side you will be presented with an interface to provide test input and validate the service response:


5.       In the mobile GUI editor, create a new pagsearchCustomers, and add the following elements:
        Text Boxcustsearchinput
        Buttonsearchbutton
        List Viewcustlistview

6.       In the binding section of the Search button, bind the button with the GET / search:query() web service. Map the custsearchinput textboto the query route parameter in the data section. This actionwill bind the search texto the query route parameter. Note that the query route parameter is already mapped tgetSearchCsutomerAction.


7.       Modify the onGetSearchquery JavaScript method in MyMobileApp/www/js/ my.js to handle the RPC response:
function onGetSearchquery(response) {
// TODO Custom logic to handle server response customers = response;

var newCustomers = '';
$.each(customers, function(index, item) { newCustomers += '<li data-theme="">'
+ '<a href="#page2?empId=' + index
+ '" data-transition="none">' + item.name + '</a>' + '</li>';
});

$('#custlistview li[role!=heading]').remove();
$('#custlistview').append(newCustomers).listview('refresh');
}

8.       Make sure thayou link the Search page from the index page using a button.

9.       Now run the project in native mode; you will be able to see the search page, like the one shown in the following screenshot:


What just happened?
We have now created neweb services for the existing cloud-connected mobile application and havtested the mobile app in a native emulator. With Zend Studio 10, you can see the simplicity in building mobile apps which are supported bweb services running on the cloud.
Q1. Which of the following platforms are supported in Zend Studio 10 for native mobile application development?

1.       Android
2.       Firefox OS
3.       MeeGo
4.       Brew

Q2. Which of the following web services are not supported bZend Server Gatewafor building cloud-connected mobile applications?

1.      RPC
2.      SOAP
3.      REST


Summary


Cloud-connected mobile applications are a greastep bZend towards enabling PHP developerto build and support mobile apps using the cloud platform. With CCM, Zend is offering an extremely robust, yet simple-to-use platform for building these applications.

Không có nhận xét nào:

Đăng nhận xét