PHPackages                             strongsquirrel/yii2-crud - 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. [Admin Panels](/categories/admin)
4. /
5. strongsquirrel/yii2-crud

ActiveYii2-extension[Admin Panels](/categories/admin)

strongsquirrel/yii2-crud
========================

CRUD extension for Yii2

v3.1.0(10y ago)7631[2 issues](https://github.com/StrongSquirrel/yii2-crud/issues)MITPHPPHP &gt;=5.4

Since Jun 2Pushed 10y ago5 watchersCompare

[ Source](https://github.com/StrongSquirrel/yii2-crud)[ Packagist](https://packagist.org/packages/strongsquirrel/yii2-crud)[ RSS](/packages/strongsquirrel-yii2-crud/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (0)

Yii2 CRUD
=========

[](#yii2-crud)

CRUD extension for Yii2.

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

[](#installation)

Run the [Composer](http://getcomposer.org/download/) command to install the latest stable version:

```
composer require strongsquirrel/yii2-crud @stable

```

The extension has a base functional for creating CRUD with the following actions:

- `index`: list of models
- `create`: create a model
- `update`: update a model
- `delete`: delete a model
- `view`: view a model
- `search`: search models

Usage
-----

[](#usage)

### Simple way

[](#simple-way)

Just create controller:

```
use strongsquirrel\crud\CrudController;

class AwesomeController extends CrudController
{
    public $modelClass = Model::class;
}
```

or use a special trait:

```
class AwesomeController extends YourController
{
   use strongsquirrel\crud\CrudTrait;

   public $modelClass = Model::class;
}
```

### IndexAction

[](#indexaction)

Declare the following in your controller:

```
use strongsquirrel\crud\IndexAction;

public function actions()
{
    return [
        'index' => [
            'class' => IndexAction::className(),
            'modelClass' => MyModel::className(),
            'view' => 'index', // by default
            // 'prepareDataProvider' => [$this, 'prepareDataProvider'],
            // 'checkAccess' => [$this, 'checkAccess'],
        ],
    ];
}
```

View file `index.php`:

```
echo GridView::widget([
    'dataProvider' => $dataProvider,
]);
```

### CreateAction

[](#createaction)

Declare the following in your controller:

```
use strongsquirrel\crud\CreateAction

public function actions()
{
    return [
        'create' => [
            'class' => CreateAction::className(),
            'modelClass' => MyModel::className(),
            'scenario' => MyModel::SCENARIO_DEFAULT, // by default
            'view' => 'create', // by default
            // 'findModel' => [$this, 'findModel'],
            // 'checkAccess' => [$this, 'checkAccess'],
            // 'afterSave' => [$this, 'onAfterSave'],
        ],
    ];
}
```

View file `create.php`:

```
$form = ActiveForm::begin();
echo $form->field($model, 'title');
ActiveForm::end();
```

### UpdateAction

[](#updateaction)

Declare the following in your controller:

```
use strongsquirrel\crud\UpdateAction

public function actions()
{
    return [
        'update' => [
            'class' => UpdateAction::className(),
            'modelClass' => MyModel::className(),
            'scenario' => MyModel::SCENARIO_DEFAULT, // by default
            'view' => 'update', // by default
            // 'findModel' => [$this, 'findModel'],
            // 'checkAccess' => [$this, 'checkAccess'],
            // 'afterUpdate' => [$this, 'onAfterSave'],
        ],
    ];
}
```

View file `update.php`:

```
$form = ActiveForm::begin();
echo $form->field($model, 'title');
ActiveForm::end();
```

### DeleteAction

[](#deleteaction)

Declare the following in your controller:

```
use strongsquirrel\crud\DeleteAction

public function actions()
{
    return [
        'delete' => [
            'class' => DeleteAction::className(),
            'modelClass' => MyModel::className(),
            // 'findModel' => [$this, 'findModel'],
            // 'checkAccess' => [$this, 'checkAccess'],
            // 'afterDelete' => [$this, 'onAfterDelete'],
        ],
    ];
}
```

### ViewAction

[](#viewaction)

Declare the following in your controller:

```
use strongsquirrel\crud\ViewAction

public function actions()
{
    return [
        'view' => [
            'class' => ViewAction::className(),
            'modelClass' => MyModel::className(),
            'view' => 'view', // by default
            // 'findModel' => [$this, 'findModel'],
            // 'checkAccess' => [$this, 'checkAccess'],
        ],
    ];
}
```

View file `view.php`:

```
echo DetailView::widget([
    'model' => $model,
]);
```

### SearchAction

[](#searchaction)

Declare the following in your controller:

```
use strongsquirrel\crud\SearchAction

public function actions()
{
    return [
        'index' => [
            'class' => SearchAction::className(),
            'modelClass' => MySearchModel::className(),
            'scenario' => MySearchModel::SCENARIO_DEFAULT, // by default
            'view' => 'search', // by default
            'formMethod' => SearchAction::FORM_METHOD_GET, // by default
            'searchMethod' => 'search', // by default
            'searchOptions' => [], // by default
            // 'checkAccess' => [$this, 'checkAccess'],
        ],
    ];
}
```

Add search method to your class model:

```
class MySearchModel extends Model
{
    // ...

    /**
     * The search method.
     * Should return an instance of [[DataProviderInterface]].
     *
     * @param array $options your search options
     *
     * @return ActiveDataProvider
     */
    public function search(array $options = [])
    {
        $query = MyModel::find();
        if ($this->validate()) {
            $query->filterWhere($this->getAttributes());
        }

        if (!empty($options['active'])) {
            $query->andWhere(['status' => MyModel::STATUS_ACTIVE]);
        }

        return new ActiveDataProvider(['query' => $query]);
    }
}
```

View file `search.php`:

```
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $filterModel,
]);
```

Recipes
-------

[](#recipes)

#### Changing CrudTrait actions

[](#changing-crudtrait-actions)

```
namespace app\controllers;

use app\models\News;
use strongsquirrel\crud\CrudTrait;

class NewsController extends Controller
{
    use CrudTrait {
        actions as traitActions;
    }

    public $modelClass = News::class;

    public function actions()
    {
        $actions = $this->traitActions();

        unset($actions['view']);
        unset($actions['update']);
        unset($actions['delete']);
        unset($actions['search']);

        $actions['create']['afterSave'] = function () {
            return $this->redirect('index');
        };

        return $actions;
    }
}
```

#### Additional parameters in view

[](#additional-parameters-in-view)

```
namespace app\controllers;

use app\models\City;
use app\models\User;
use strongsquirrel\crud\UpdateAction;
use strongsquirrel\crud\ViewAction;

class UsersController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'update' => [
                'class' => UpdateAction::className(),
                'modelClass' => User::className(),
                'params' => [
                    'cities' => [$this, 'getCities'],
                    'title' => 'Update User',
                ],
            ],
            'view' => [
                'class' => ViewAction::className(),
                'modelClass' => User::className(),
                'params' => function (User $model) {
                    return [
                        'posts' => function (User $model) {
                            return $model->posts;
                        },
                        'city' => $model->city,
                        'cities' => [$this, 'getCities'],
                    ];
                },
            ],
        ];
    }

    /**
     * @return City[]
     */
    public function getCities()
    {
        return City::findAll();
    }
}
```

License
-------

[](#license)

The MIT License (MIT). See [LICENSE.md](https://github.com/StrongSquirrel/yii2-crud/blob/master/LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 52% 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.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~46 days

Total

7

Last Release

3852d ago

Major Versions

v1.1.0 → v2.0.02015-06-11

v2.2.0 → v3.0.02015-12-03

### Community

Maintainers

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

---

Top Contributors

[![frostealth](https://avatars.githubusercontent.com/u/1785217?v=4)](https://github.com/frostealth "frostealth (13 commits)")[![chuprik](https://avatars.githubusercontent.com/u/802946?v=4)](https://github.com/chuprik "chuprik (11 commits)")[![nismangulov](https://avatars.githubusercontent.com/u/6184888?v=4)](https://github.com/nismangulov "nismangulov (1 commits)")

---

Tags

yii2crudactionsaction

### Embed Badge

![Health badge](/badges/strongsquirrel-yii2-crud/health.svg)

```
[![Health](https://phpackages.com/badges/strongsquirrel-yii2-crud/health.svg)](https://phpackages.com/packages/strongsquirrel-yii2-crud)
```

###  Alternatives

[schmunk42/yii2-giiant

Gii CRUD generator for Yii 2 Framework

269493.0k17](/packages/schmunk42-yii2-giiant)

PHPackages © 2026

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