yii2-crud-toolkit

Build your controllers as LEGO!

  • 所有者: voskobovich/yii2-crud-toolkit
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Yii2 CRUD Toolkit

It is a framework to quickly build controllers for your Yii2 application.

Example

Your controller can look like this

<?php

namespace app\controllers;

use voskobovich\alert\helpers\AlertHelper;
use voskobovich\crud\actions\UpdateAction;
use voskobovich\crud\actions\ViewAction;
use Yii;
// and more namespases ...

/**
 * Class ProfileController.
 */
class ProfileController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function actions()
    {
        $successCallback = function () {
            Yii::$app->session->setFlash('success', 'Saved successfully!');
        };

        $errorCallback = function () {
            Yii::$app->session->setFlash('error', 'Error saving!');
        };

        $webUser = Yii::$app->user;

        return [
            'update' => [
                'class' => UpdateAction::className(),
                'modelClass' => ProfileUpdateForm::className(),
                'primaryKey' => $webUser->id,
                'redirectUrl' => false,
                'successCallback' => $successCallback,
                'errorCallback' => $errorCallback,
            ],
            'password' => [
                'class' => UpdateAction::className(),
                'modelClass' => ProfilePasswordForm::className(),
                'primaryKey' => $webUser->id,
                'redirectUrl' => ['password'],
                'viewFile' => 'password',
                'successCallback' => function () {
                    Yii::$app->session->setFlash('success', 'Password changed');
                },
                'errorCallback' => $errorCallback,
            ],
            'photo' => [
                'class' => UploadAction::className(),
                'modelClass' => ProfilePhotoForm::className(),
                'primaryKey' => $webUser->id,
                'viewFile' => 'photo',
                'redirectUrl' => false,
                'successCallback' => false,
                'errorCallback' => false,
            ],
            'photo-delete' => [
                'class' => UpdateAction::className(),
                'modelClass' => ProfilePhotoDeleteForm::className(),
                'primaryKey' => $webUser->id,
                'viewFile' => false,
                'redirectUrl' => ['update'],
                'successCallback' => false,
                'errorCallback' => false,
            ],
            'contacts' => [
                'class' => ViewAction::className(),
                'modelClass' => User::className(),
                'loadedModel' => $webUser->identity,
                'viewFile' => 'contacts',
            ],
        ];
    }
}

Action Params
---, Param name, Description, ---------------, ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------, modelClass, Class name of your ActiveRecord model or form which extend voskobovich\base\forms\FindableFormAbstract from yii2-base-toolkit., viewFile, The name of view file., viewParams, The view additional params., redirectUrl, The route which will be redirected after the user action., scenario, The scenario to be assigned to the model before it is validated and updated., primaryKeyParam, The name of the GET parameter that stores the primary key of the model., successCallback, Is called when a successful result., errorCallback, Is called when a failed result., beforeRun, This method is called right before run() is executed. You may override this method to do preparation work for the action run. If the method returns false, it will cancel the action., afterRun, This method is called right after run() is executed. You may override this method to do post-processing work for the action run., loadedModel, The previously loaded object of modelClass., > This is only the basic parameters of the action.
For details see the source code.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist voskobovich/yii2-crud-toolkit "^3"

or add

"voskobovich/yii2-crud-toolkit": "^3"

to the require section of your composer.json file.

CODE ECOLOGY

To auto fix the code format:

./vendor/bin/php-cs-fixer fix

主要指標

概覽
名稱與所有者voskobovich/yii2-crud-toolkit
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證
所有者活动
創建於2015-07-24 12:16:50
推送於2017-04-08 17:06:02
最后一次提交2017-04-08 20:05:56
發布數4
最新版本名稱v2.0.1 (發布於 2016-02-13 18:13:40)
第一版名稱v1.0.0 (發布於 2015-07-24 18:00:49)
用户参与
星數11
關注者數3
派生數2
提交數104
已啟用問題?
問題數0
打開的問題數0
拉請求數1
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?