PHPackages                             goodnickoff/yiirestmodel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. goodnickoff/yiirestmodel

ActiveYii-extension

goodnickoff/yiirestmodel
========================

Yii RESTful API

121778PHP

Since Nov 11Pushed 8y ago5 watchersCompare

[ Source](https://github.com/hutnikau/yiirestmodel)[ Packagist](https://packagist.org/packages/goodnickoff/yiirestmodel)[ RSS](/packages/goodnickoff-yiirestmodel/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Extension for implementation RESTful API
========================================

[](#extension-for-implementation-restful-api)

Installation
------------

[](#installation)

Extract files under protected/extensions.

Add to config:

```
    array('api//list', 'pattern'=>'api/', 'verb'=>'GET'),
    array('api//view', 'pattern'=>'api//', 'verb'=>'GET'),

    array('api//create', 'pattern'=>'api/', 'verb'=>'POST'),

    array('api//update', 'pattern'=>'api//', 'verb'=>'PUT'),
    array('api//update', 'pattern'=>'api/', 'verb'=>'PUT'),

    array('api//delete', 'pattern'=>'api//', 'verb'=>'DELETE'),
    array('api//delete', 'pattern'=>'api/', 'verb'=>'DELETE'),

```

Documentation
-------------

[](#documentation)

Usage
-----

[](#usage)

Create module and controllers in it.

Controller example:

```
class UsersController extends ApiController
{
    public $safeAttributes = array(
        'id', 'first_name',  'middle_name', 'last_name', 'email',
    );

    public function __construct($id, $module = null)
    {
        $this->model = new User('read');
        parent::__construct($id, $module);
    }

    /**
     * Function returns user data
     * @method GET
     */
    public function actionView()
    {
        if (!Yii::app()->user->checkAccess('getUser')) {
            $this->accessDenied();
        }
        $this->getView();
    }

    /**
     * Function returns user list
     * @method GET
     */
    public function actionList()
    {
        if (!Yii::app()->user->checkAccess('getUser')) {
            $this->accessDenied();
        }

        $this->getList();
    }

    /**
     * Function creates new user
     * @method POST
     */
    public function actionCreate()
    {
        if (!Yii::app()->user->checkAccess('createUser')) {
            $this->accessDenied();
        }

        $this->model->setScenario('create');

        $this->create();
    }

    /**
     * Function updates user.
     * @method PUT
     */
    public function actionUpdate()
    {
        if (!Yii::app()->user->checkAccess('updateUser')) {
            $this->accessDenied();
        }

        $this->model->setScenario('update');

        $this->update();
    }

    /**
     * Function deletes user.
     * @method DELETE
     */
    public function actionDelete()
    {
        if (!Yii::app()->user->checkAccess('deleteUser')) {
            $this->accessDenied();
        }

        $this->model->setScenario('delete');

        $this->delete();
    }

    public function getRelations()
    {
        return array(
            'comments'=>array(          // relation GET parameter name (...?with=comments)
                'relationName'=>'comments',  //model relation name
                'columnName'=>'comments',    //column name in response
                'return'=>'array'            //return array of arrays or array of models
            )
        );
    }
}
```

### Get records

[](#get-records)

```
GET: /user - all users
GET: /user/2 - user with id=42

```

#### search and filtering

[](#search-and-filtering)

```
{"name":"alex", "age":"25"} — WHERE name='alex' AND age=25
[{"name":"alex"}, {"age":"25"}]  WHERE name='alex' OR age=25

```

The comparison operator is intelligently determined based on the first few characters in the given value. In particular, it recognizes the following operators if they appear as the leading characters in the given value:

- &lt;: the column must be less than the given value.
- > : the column must be greater than the given value.
- &lt;=: the column must be less than or equal to the given value.
- > =: the column must be greater than or equal to the given value.
- &lt;&gt;: the column must not be the same as the given value.
- =: the column must be equal to the given value.

Examples:

```
GET: /users?filter={"name":"alex"} — user with name alex
GET: /users?filter={"name":"alex", "age":">25"} — user with name alex AND age greater than 25
GET: /users?filter=[{"name":"alex"}, {"name":"dmitry"}] — user with name alex OR dmitry
GET: /users?search={"name":"alex"} — user with name contains the substring alex (alexey, alexander, alex)

```

#### relations

[](#relations)

```
GET: /user/1?with=comments,posts — get user data with comments and posts array (comma separated list of relations in `with` GET parameter)
{
    "id":"1",
    "first_name":"Alex",
    "comments":[{"id":"1","text":"..."}, {"id":"2","text":"..."}],
    "posts":[{"id":"1","content":"..."}, {"id":"2","content":"..."}],
    ...
}

```

### Deleting

[](#deleting)

```
DELETE: /user/42 - delete user with id = 42
DELETE: /user  - delete all users
DELETE: /user?filter={"first_name":"Alex"} - delete users with name 'Alex'

```

### Create

[](#create)

```
POST: /user - create new user

```

### Create collection

[](#create-collection)

```
POST: /user - create new users

```

pass POST parameters:

```
[
    {"name":"admin"},
    {"name":"guest"}
]

```

Creating two users 'admin' and 'guest'

### Update

[](#update)

```
PUT: /user/42 - update user with id = 42

```

#### Update collection

[](#update-collection)

```
PUT: /user

```

pass POST parameters:

```
[
    {"id":"1","name":"admin"},
    {"id":"2","name":"guest"}
]

```

update users with id 1 and 2

### limit, offset, order

[](#limit-offset-order)

```
GET: /users/?offset=10&limit=10
GET: /users/?order=id DESC
GET: /users/?order=id ASC
GET: /users/?order=parent_id ASC,ordering ASC
GET: /users/?order=comment.id&with=comment

```

### Response format

[](#response-format)

By default response is sent in the format of JSON. To change the format of response pass `format` GET parameter with value `xml`

```
GET: /users?format=xml

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd082ab008df5d9c07f3d93666f5fea2c7fe8a22071819eb800a5cbe85b4f67f?d=identicon)[hutnikau](/maintainers/hutnikau)

---

Top Contributors

[![oledje](https://avatars.githubusercontent.com/u/2511332?v=4)](https://github.com/oledje "oledje (3 commits)")

### Embed Badge

![Health badge](/badges/goodnickoff-yiirestmodel/health.svg)

```
[![Health](https://phpackages.com/badges/goodnickoff-yiirestmodel/health.svg)](https://phpackages.com/packages/goodnickoff-yiirestmodel)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
