Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to override model #442

Open
ishitat opened this issue Jul 4, 2020 · 2 comments
Open

Want to override model #442

ishitat opened this issue Jul 4, 2020 · 2 comments

Comments

@ishitat
Copy link

ishitat commented Jul 4, 2020

Hi,

I want to override model to add more fields in the model.
model - authitem

How can I override it?

@prabowomurti
Copy link

I would like to override the rules() of AuthItem model but still don't know how to do it.

@prabowomurti
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants