Open ishitat opened 4 years ago
I would like to override the rules()
of AuthItem model but still don't know how to do it.
My first attempt is to install this package by the archives, and modify everything we need on our own (for example) components
folder. (https://github.com/mdmsoft/yii2-admin#install-from-the-archive)
But our fellow programmer comes to this alternative solution:
Change web.php
(or config.php for Advanced Template yii)
'modules' => [
'access-control' => [
'defaultUrlLabel' => 'Access Control',
'class' => 'mdm\admin\Module',
'layout' => '@app/views/layouts/access-control.php',
'viewPath' => '@app/views/admin',
'controllerMap' => [
'route' => [
'class' => 'app\controllers\AccessControlRoleController', // this will be our customized controller file
],
],
],
],
On app\controllers\AccessControlRoleController.php
we override the existing RouteController from mdm\controllers
, and use our own AuthItem
model :
<?php
namespace app\controllers;
use Yii;
use app\models\AuthItem; // our own AuthItem model
use mdm\admin\components\Configs;
use mdm\admin\controllers\RoleController;
class AccessControlRoleController extends RoleController
{
public function actionCreate()
{
// override the parent actionCreate()
}
protected function findModel($id)
{
// override here...
}
//... and so on
}
On our own AuthItem.php
, we can edit rules()
, fields()
or override any other function.
Hi,
I want to override model to add more fields in the model. model - authitem
How can I override it?