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

User CRUD


We have already developed part of the code needed for this function, but we will rewrite part of it because, in the meantime, we have made changes to the database that will affect the functionality of our application. What we are going to develop next is similar to the previous CRUD sections. Let's start with the API controller.

Creating the controller (API)

As we did in Chapter 7, The Backoffice Module (Part 1), with hashtag and category, we will need to create a controller for the user. Create a new file in modules/Api/Controller/ and name it UsersController.php. Then, write the following code:

<?php
namespace App\Api\Controllers;

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

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