Complete code for Tutorial 7 - Creating a simple REST API

Does anyone have the complete code to make Tutorial 7 work? I've tried following the instructions in the tutorial and I can't make it work. For example, nowhere does it tell you where to put the code that I presume makes the connection to the database.

edited May '16

Code that takes care of database connection is often put into services container. The basic idea is to bootstrap your application in that manner. I'm just about to finish development of one Micro app which primary task is to handle RESTful queries. I can publish it on github when finished. It might not be best suited for beginners, since it extends Phalcon with various components to glue everything together, i.e. handlers are defined with a dedicated service component, and business logic is implemented in controllers with custom models / ORM.

In short, if you follow the tutorial on Phalcon site, your structure should looks like this:

  • my-rest-api/
  • models/Robots.php
  • index.php

Basically, everything goes into index.php. Only part which defines Model goes into Robots.php.



986

Thanks Stamster. The file structure is how I have the files currently. Once I added the DB code to the beginning of index.php, removing the redundant stuff, it all worked. Thanks again.

You're welcome. Happy coding with Phalcon! :)