Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Tutorial 5: Show Post on Detail Screen

Tutorial 5: Show Post on Detail Screen

When clicking on an item in the Home App screen, it navigates to a detail screen. And display data response from Detail Resource API
Detail Resource API pattern: "url/restful_api/mobile/post/post_id?access_token=token"
Logic code of the API implements in method findOne() of PostApi class. ID parameter resolves automatically. The resolver instance is a helper class help to extract or validate parameters from the request.
PostApi.php
class PostApi extends AbstractResourceApi implements MobileAppSettingInterface
{
/.../
public function findOne($params)
{
$id = $this->resolver->resolveId($params);
// Todo: Loading data form database and build as resource
$post = new PostResource([
'post_id' => $id,
'title' => "Post's title example " . $id,
'description' => "Post's description " . $id,
'text' => "Post's Full Text " .$id
]);
return $this->success($post);
}
}
 
The result of the detail screen as following
Image Added   Image Added