PHP code example of unyii2 / yii2-panel

1. Go to this page and download the library: Download unyii2/yii2-panel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

unyii2 / yii2-panel example snippets



echo \unyii2\yii2panel\PanelWidget::widget([
    'name' => 'exportSettings',
    'params' => [
        'docId' => 777
    ]
]);


    public function actionCreate()
    {
    
        $model = new RkInvoiceForm();
        if($model->load($request->post()) && $model->save()) {
            $panelLogic = Yii::createObject([
                'class' => PanelLogic::class,
                'name' => 'LietvedibaRkInvoiceSave',
                'params' => [
                    'modelRecordId' => $model->id
                ]
            ]);
            $panelLogic->run();
            return $this->redirect(['view', 'id' => $model->id]);
        }
        return $this->render('create', [
            'model' => $model,
        ]);
       
    }

        'invoices' => [
            'class' => 'd3modules\d3invoices\Module',
            'panels' => [
                /** for widget */
                'exportSettings' => [
                    [
                        'route' => 'd3accexport/invoice-panel/document-settings',
                        'params' => [
                            'docId' => 13 // action parameter value
                         ]
                        'tag' => 'div', // optinal. Add enclosing tag to panel  
                        'options' => ['class' => 'col-sm-8 col-md-6 col-lg-4'] //enclosing tag options
                     ]
                 ],
                 /** for panel logic */
                 'LietvedibaRkInvoiceSave' => [
                    [
                        'route' => 'deal/panel/save'
                    ]
                ],
            ],
        ],


        'invoices' => [
            'class' => 'd3modules\d3invoices\Module',
            'controllerMap' => [
                'settings' => [
                    'class' => 'yii3\persons\controllers\SettingsController',
                    'panels' => [
                        'UserSettingsProvileLeft' =>
                            [
                                [
                                    'route' => 'myauth/panel/show-qrc'
                                 ]
                            ]
                    ]
                ],
            ],

'params' => [
    'panelWidget' => [
        'dashboard' => [
            'last' =>  [
                [
                    'route' => 'delivery/panel/transit-declarations',
                    /**  
                     * parameters for action method:
                     * public function actionMyTransitDeclarations(array $statusIdList): string 
                     */
                    'params' => [
                        'statusIdList' => [5, 20]
                    ]                    
                ]
            ],
        ]
    ],
]




namespace d3modules\d3accexport\controllers;

use unyii2\yii2panel\Controller;
use yii\filters\AccessControl;

class InvoicePanelController extends Controller
{

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::class,
                'rules' => [
                    /**
                    * standard definition
                    */
                    [
                        'allow' => true,
                        'actions' => [
                            'document-settings',
                        ],
                        'roles' => [
                            'DocSetting',
                        ],
                    ],
                    
                    /**
                    * roles define in panel module config. 
                    *   Example of edi module config:
                    *        'edi' => [
                    *            'class' => 'd3yii2\d3edi\Module',
                    *            'accessRulesMessageRoles' => ['Depo3EdiFull']
                    *        ],
                    *   In Module add property:
                    *        class Module extends D3Module
                    *           public $accessRulesMessageRoles;
                    *           ....
                    */
                    [
                        'allow' => true,
                        'actions' => [
                            'message',
                        ],
                        'roles' => $this->module->rulesMessageRoles??['@'],
                    ],                    
                ],
            ],
        ];
    }

    /** for widget */
    public function actionDocumentSettings()
    {
        return $this->render('setting_grid',[]);

    }

    /** for widget */
    public function actionMessage()
    {
        return $this->render('message',[]);

    }

    /** for controller logic */
    public function actionSave(int $modelRecordId): bool
    {
        if (!$model = DealInvoice::findOne(['invoice_id' => $modelRecordId])) {
            $model = new DealInvoice();
            $model->invoice_id = $modelRecordId;
        }

        $request = Yii::$app->request;
        if ($model->load($request->post())
            && $model->deal_id
            && $model->save()
        ) {
            return true;
        }

        if ($model->hasErrors()) {
            throw new \Exception(json_encode($model->getErrors()));
        }
        return true;
    }

}