Extending a class Controller from parent module to all sub module


(Ahmadfadlydziljalal) #1

How do you extend the module correctly?
The case is, I have a module with subModule and subSubModule in it.

The arrangement is as follows.

- models
	- jakarta
		- admin
			- BillOfLading
	- surabaya
		- admin
			- BillOfLading
			
			
- modules
	- branch ( Parent Module )
		- controllers
			- DefaultController
		- models
		- views
		- jakarta( Sub Module )					
			- controllers
			- models
			- views
			- admin ( Sub Sub Module)				
				- controllers
					- BillOfLadingController
				- models
					- BillOfLadingSearch
				- views
					- bill-of-lading
		- surabaya( Sub Module )					
			- controllers
			- models
			- views
			- admin ( Sub Sub Module)				
				- controllers
					- BillOfLadingController
				- models
					- BillOfLadingSearch
				- views
					- bill-of-lading

All are generated through gii.
Basically the BillOfLadingControlller in both submodules namely Jakarta and Surabaya is the same,
only different tables in the database.

If in submodule jakarta is in db_jakarta / bill-of-lading,
and in submodule surabaya it is in db_surabaya / bill-of-lading

For the BillOfLadingController in the subModule Jakarta,

namespace app\modules\branch\jakarta\admin\controllers;

use app\models\jakarta\admin\BillOfLading;
use app\modules\jakarta\admin\models\BillOfLadingSearch;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class BillOfLadingController extends Controller{
	// Some code generate By gii
	// action Create, Delete, Update, View
}\\

And for the BillOfLadingController in Surabaya submodule,

namespace app\modules\branch\surabaya\admin\controllers;

use app\models\surabaya\admin\BillOfLading;
use app\modules\surabaya\admin\models\BillOfLadingSearch;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class BillOfLadingController extends Controller{
	// Some code generate By gii
	// action Create, Delete, Update, View
}

Is there a better way to use trait, interface, or extend.
So there is no need to define each BillOLadingController class.

I think there is a ParentBillOfLadingController base class in the parent module branch,
then each BillOfLadingController at each submodule is extend from ParentBillOfLadingController.

So if the ParentBillOfLadingController changes business processes, all children also change.
How to implement it ?

We appreciate all responses.
Thanks