2

I have been having trouble finding any up to date tutorials on Apigility - and nothing when it comes to writing a code connected service across multiple tables.

Say I have two tables, one to manage blog categories, the other to manage blog entries...

Category Table
+------------------+---------+
| CategoryID       | int     |
| CategoryName     | varchar |
| Tags             | varchar |
+------------------+---------+

Blog Table
+------------------+---------+
| BlogID           | int     |
| CategoryID       | int     |
| Title            | varchar |
| BlogText         | text    |
+------------------+---------+

Now I'd like to create a rest service like so...

/blog/:id

Which should return an entity like so...

BlogID
Title
BlogText
CategoryID
CategoryName
Tags

Can someone please provide me with some sample code, an example, a tutorial, something that is current that I can use with stock Apigility (not using Doctrine, etc).

When using Apigility, it creates 4 stub classes - how can these be filled to make it just work?

Thanks

1 Answers1

0

You need to create a code-connected resource (api service) and fill up the Resource class yourself to handle GET, POST, DELETE, etc, yourself.

The best 2 advices I can give on ZF2 related tasks:

  • Use a debugger
  • Read the source code, read the tests

While digging through Apigility source code, I learned that a DB-Connected resource is in fact a pre-configured Code-Connected resource. So here is an example Code-Connected resource that you can get started with: https://github.com/zfcampus/zf-apigility/blob/master/src/DbConnectedResource.php

You only have to extend it to work with multiple tables.

Clément Prévost
  • 8,000
  • 2
  • 36
  • 51
  • Your answer helped me understand the gap between a DB Connected resource and a code connected resource. This tutorial was also helpful... http://techportal.inviqa.com/2013/12/03/create-a-restful-api-with-apigility/ – Robert Rusler Aug 23 '15 at 11:50