Book Image

Learning Phalcon PHP

Book Image

Learning Phalcon PHP

Overview of this book

Table of Contents (17 chapters)
Learning Phalcon PHP
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Writing a fully functional REST module with Phalcon PHP


Before starting, I recommend that you use a RESTful client that will help you test things faster. Personally, I prefer DHC (it's a Chrome extension), which can be found at https://chrome.google.com/webstore/detail/dhc-resthttp-api-client/aejoelaoggembcahagimdiliamlcdmfm?hl=en.

We are going to develop the CRUD operations for Articles, Categories, Hashtags and Users. Let's start with Articles.

Articles

We have already created the controller, so by executing a GET method on https://learning-phalcon.localhost/api/v1/articles, you should get a response. Let's implement the article manager for the articles listing so that we can retrieve real data.

First of all, we will make some changes to the Article model and overwrite the toArray() method. Open modules/Core/Models/Article.php and append the following code:

public function getTranslations($arguments = null) {
  return $this->getRelated('translations', $arguments);
}

public function getCategories...