voskobovich / yii2-crud-toolkit
The foundation for implementing CRUD operations for Yii2
Installs: 552
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 4
Forks: 2
Open Issues: 0
Type:yii2-toolkit
Requires
- php: >=5.4.0
- voskobovich/yii2-base-toolkit: ^2.1.0
- yiisoft/yii2: ^2.0.0
This package is not auto-updated.
Last update: 2024-11-09 18:48:53 UTC
README
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
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