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

Creating the module structure

We have already created the basic structure in the previous chapters. The directory structure should look like this:

This is okay. What we need to do here is enable the routing and add some methods to BaseController so that we can move forward. Let's start this process by performing the following steps:

  1. Open the routing.php file from the api module, delete its content, and put in this code:

    $versions = [
      'v1' => '/api/v1',
      'v2' => '/api/v2'
    // Articles group
    $articles = new \Phalcon\Mvc\Router\Group(array(
      'module' => 'api',
      'controller' => 'articles'
    $articles->addGet('', array(
      'module' => 'api',
      'controller' => 'articles',
      'action' => 'list'
  2. Next, we add an array with the available versions of our API, and we tell the router to remove extra slashes. Therefore, a request to /api/v1...