Book Image

Learning Phalcon PHP

By : Calin Rada, Ioan C Rada
Book Image

Learning Phalcon PHP

By: Calin Rada, Ioan C Rada

Overview of this book

Table of Contents (17 chapters)
Learning Phalcon PHP
About the Author
About the Reviewers

Article CRUD

We partially wrote some code for this part. It is probably working for you, but you will be changing mostly everything in it. The API controller has already been developed, so we can move directly on to ArticleManager to refactor it.

The Controller (API)

The code for this controller is similar to that of the rest of the controllers. Let's see what it looks like. Open the file located at modules/Api/Controllers/ArticlesController.php, clear its content, and write the following code:

namespace App\Api\Controllers;

class ArticlesController extends BaseController{
  public function updateAction($id) {
    try {
      $manager = $this->getDI()->get('core_article_manager');

      if ($this->request->getHeader('CONTENT_TYPE') == '       application/json') {
        $data = $this->request->getJsonRawBody(true);
      } else {
        $data = $this->request->getPut();

      if (count($data) == 0) {
        throw new \Exception('Please provide...