andreykluev/yii2-crud-actions

Yii2 crud actions

Installs: 259

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 1

Open Issues: 1

Type:yii2-extension

0.2 2015-04-01 06:23 UTC

This package is not auto-updated.

Last update: 2025-04-22 06:31:53 UTC


README

Установка

В composer.json:

"require": {
	...
	"andreykluev/yii2-crud-actions": "dev-master"
},

Варианты использования

use andreykluev\crudactions\crudActionCreate;
use andreykluev\crudactions\crudActionDelete;
use andreykluev\crudactions\crudActionUpdate;

use common\models\Product;

class CatalogController extends AppController
{

	...

	public function actions()
	{
		return array(
			'insert' => [
				'class' => crudActionCreate::className(),
				'model' => new Product(),
				'view' => 'update-album',
				'onBeforeAction' =>  [$this, 'beforeSaveProduct'],
				'onAfterAction' =>  [$this, 'afterSaveProduct'],
			],
			
			'update' => [
				'class' => crudActionUpdate::className(),
				'modelClass' => Product::className(),
                'attributes' => [
                    'id_user' => Yii::$app->user->identity->getId(),
                    'id_album' => Yii::$app->request->get('idAlbum', 0),
                ],
				'view' => 'update-album',
				'onBeforeAction' =>  [$this, 'beforeSaveProduct'],
				'onAfterAction' =>  [$this, 'afterSaveProduct'],
			],
			
			'delete' => [
				'class' => crudActionDelete::className(),
				'modelClass' => Product::className(),
				'onBeforeAction' =>  [$this, 'beforeDeleteProduct'],
				'onAfterAction' =>  [$this, 'afterDeleteProduct'],
			],

			...
		);
	}

	...
	
	public function beforeSaveProduct()
	{
		// Ваш код
	}
	
	public function afterSaveProduct($isSave = false)
	{
		// Ваш код
	}
	
	public function beforeDeleteProduct()
	{
		// Ваш код
	}
	
	public function afterDeleteProduct($isDelete = false)
	{
		// Ваш код
	}