Book Image

Web Application Development with Yii 2 and PHP

By : Mark Safronov, Jeffrey Winesett
Book Image

Web Application Development with Yii 2 and PHP

By: Mark Safronov, Jeffrey Winesett

Overview of this book

<p>Yii is a high performance PHP framework used for rapid web application development. It is well designed, well supported, easy to learn, and easy to maintain. This book embraces the learn-by-example methodology to show you the most important features of the Yii 2 framework. Throughout the course of this book, you will build a simple real-world application; each chapter will introduce you to a new functionality and show you how to tweak your application. Instead of trying to be an all-encompassing reference about the framework, this is a walkthrough of the really important pieces of information that you have to understand in detail.</p> <p>You will learn how to use Yii's active record and CRUD scaffolding to manage the data in your database. Authentication, extensions, events and behaviors, and route management are just some of the many other features of Yii that you will learn from this book. By the end of this book, you will have a basic CRM application that is all set for service!</p>
Table of Contents (22 chapters)
Web Application Development with Yii 2 and PHP
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Building the API module


We have two controller actions currently in our system, which:

  • Are not needed for the user interface

  • Provide the API-like representation of the information in the system

All this makes these actions perfect targets for our practice in building modules. Let's make an API module that will contain the actions currently reachable by the /services/json and /services/yaml routes.

The following use cases should be supported:

  • The GET request to the /api/services/json route should return the list of attributes of all registered services in the JSON format

  • The GET request to the /api/services/yaml route should return the list of attributes of all registered services in the YAML format

We define result in JSON format as the string that can be converted to the PHP data structures without error using the yii\helpers\Json::decode() method.

We define the result in YAML format as the string that can be converted to the PHP data structures without error using the Symfony\Component\Yaml\Yaml...