restyii 16

A RESTful extension for Yii.


Written in PHP by 2 contributors


Need Support?

we offer maintenance, support and development services for all our open source projects.

Contact Us


A RESTful HATEOAS compliant extension for Yii. Allows your application to serve and accept JSON, JSONP, XML, CSV or HTML using the same code. The JSON and XML variants are based on the HAL media type.

WARNING: Pre-alpha software, use at your own risk.


Install using composer. Requires php 5.3 or later.

Restyii makes use of a custom WebApplication that replaces the Yii default. For this reason it's necessary to replace existing calls to



Yii::createApplication('Restyii\\Web\\Application', $config)

in your index.php file.

Server Configuration.

Example Restyii server application config

Yii::setPathOfAlias('vendor', __DIR__.'/../../vendor'); // the path to the composer vendors dir
return array(
  'name' => 'Restyii Demo',
  'description' => 'This is a description of the application!',
  'import' => array(
  'modules' => array(
          // If removed, Gii defaults to localhost only. Edit carefully to taste.
  'components' => array(
        'urlManager' => array(
            'rules' => array(
                '' => array('/default/index'),
                array('class' => 'Restyii\\Web\\UrlRule'),

Restyii comes with a Gii code generator that makes generating resources easy.

Client Configuration.

Example Restyii client application config

return array(
  'name' => 'Restyii Client Demo',
  'import' => array(
  'components' => array(
        'api' => array(
            'class' => 'Restyii\\Client\\Connection',
            'baseUrl' => 'http://yourapihostname/',


Restyii follows the RAVE application architecture. RAVE is quite similar to MVC, but there are some important differences, RAVE stands for:

  • Resources
  • Actions
  • Views
  • Events

Importantly, Resources, Actions, Views and Events all describe themselves. This allows the RAVE application to be self-documenting.


Resources are analogous to the Model in MVC, but they have some key differences.

  • Individual resources are explicitly tied to particular URLs.
  • Resources know how to link to themselves and to related resources.
  • Resources know how to describe themselves and their attributes.
  • Resources know how to format their own attributes.

In RAVE, the bulk of your business logic should be placed in resources, RAVE embraces the fat model approach.


Actions are analogous to the operations performed by a Controller in MVC.

  • Actions should accept any kind of resource. This promotes code reuse and is made possible by the rich meta data resources provide.
  • Actions know which http headers and query string parameters to expect and how to describe them.
  • Actions are associated with a specific HTTP verb that is used to perform an action, e.g. DELETE for delete actions.
  • Actions return a HTTP status code along with their data.

Actions usually operate either on individual resources or collections of resources.


RAVE Views are effectively identical to views in MVC. In Restyii they are used to decorate data (usually as HTML) when the client requests something other than XML, JSON etc.


Events are triggered by resources when they change state in some way, such as when a particular model is created or updated. RAVE events are usually published to a message bus or a pub/sub channel to allow communication with other processes in the application, for example, to allow 'realtime' notifications in the browser.

Differences from standard Yii applications

In order to implement RAVE, Restyii applications require several changes to the standard Yii way of doing things.

Some important ones:

  • The web application must be an instance of Restyii\Web\Application.

  • The default controller for all modules, including the main application, should be called DefaultController. This means the normal SiteController should be renamed. DefaultController should extend the Restyii\Controller\Root class.

  • The request (Yii::app()->request) now has a getResponse() method that returns a Restyii\Web\Response instance. This response instance is responsible for formatting and sending the data to the client.

  • Controllers always use class based actions, and controllers are explicitly tied to resource types. Resource controllers extend Restyii\Controller\Model

  • Actions always extend the Restyii\Action\Base class

  • Rather than implementing run(), actions should implement present() and perform() methods.

  • Rather than calling $this->render(...), actions should return the data for the response from within the present() and perform() methods, along with the appropriate HTTP status code.

  • Application has a schema component that introspects the application and determines the available resources, actions etc.

  • Resources extend Restyii\Model\ActiveRecord.

  • Resources have a links() method that returns the appropriate links for the current resource.

  • Resources have classLabel() and instanceLabel() methods that return the appropriate labels for the resource type and a particular resource instance.

43 other PHP projects

phpwkhtmltopdfPHP 716

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

php-pdftkPHP 213

A PDF conversion and form utility based on pdftk

yii2-localeurlsPHP 189

Automatic locale/language management for URLs

YiiRedisPHP 131

A set of wrappers for different data types in redis

yiipasswordPHP 81

Password strategies for Yii

yii2-dockerizedPHP 64

A template for docker based Yii 2 applications

YiiSolrPHP 50

A wrapper for the pecl solr library that provides common Yii constructs, such as models, data providers etc

php-shellcommandPHP 48

A simple object oriented interface to execute shell commands in PHP

Yii-Docs-GeneratorPHP 47

Generates HTML documentation for Yii applications

YiiGitPHP 36

A git wrapper for Yii, allows access to all git commands programatically

YiiElasticSearchPHP 32

Elastic Search client for Yii

YiiCurlPHP 30

A curl library for Yii

YiiStateMachinePHP 28

A state machine behavior for Yii

yii2-streamlogPHP 19

A Yii 2 log target for streams in URL format

oauth2yiiPHP 18

An OAuth2 client / server extension for the Yii framework

packagecompressorPHP 16

A Javascript/CSS compressor based on Yii's package system

localeurlsPHP 12

Automatic locale/language management for URLs

php-excel-readerPHP 12

It reads the binary format of XLS files directly and can return values and formats from any cell. This project is the fork of that, apparently, is no longer maintained.

pdfablePHP 10

A Yii extension to create PDFs with PHPWkHtmlToPdf/wkhtmltopdf

yii-api-vimPHP 8

Yii API manual plugin for VIM

xcrudcontrollerPHP 7

A base class to quickly build customized CRUD interfaces.

yii2-excel-messagePHP 7

Translate messages via Excel files

yii2-bs3activeformPHP 7

A Bootstrap 3 enhanced ActiveForm for Yii 2

php-tmpfilePHP 6

A convenience class for temporary files

handlebarsphpPHP 6

Transpiles handlebars templates into native PHP templates

Yii-Package-ManagerPHP 6

A package manager for Yii

php-orientdbPHP 5

A fast PHP driver for the OrientDB binary protocol.

yii2-apidoc-vimPHP 5

Yii2 apidoc as Vim helpfiles

YiiUsersPHP 4

User management for Yii

translatablePHP 4

Transparent attribute translation for ActiveRecords

flushablePHP 3

Yii dependency that allows to flush records from the cache

Yii-Resource-ManagerPHP 3

Helpers to allow Yii to interact with resources (files) of different types

AccessRestrictablePHP 2

A Yii ActiveRecordBehavior that automatically applies conditions for access restriction to every query.

bs3activeformPHP 2

A lightweight utility to render Bootstrap 3 forms in Yii

YiiEmailerPHP 2

Emailing functions for Yii

defaultpersisterPHP 1

Yii extension to save and restore model values in user session.

hybridauthmanagerPHP 1

An AuthManager for Yii that stores the hierarchy in a flat PHP file and the assignments in DB

YiiYaaPHP 1

YAA is an additional abstraction layer for Yii that aggregates a number of child models into a clean single model that is easy to cache

YiiLinkablePHP 1

A simple extension for Yii allowing easy and consistent access to model URLs and appropriate anchor text.


An alternative Yii2 application template for purists


Yii extension to create URLs that allow to return to a page by storing its GET Parameters on a stack.


Work with PHP files in Active Record way


simple useless twitter client