Too Many Extends I Believe. Is There A Better Way?

Hi guys, I am developing a CMS on Yii, I am almost happy on how it works, I just have 1 little things that nags me. I am sure that it is my programming and not Yii :).

Because all my websites are using kind of the same classes I have created a module as a core (the module name is "core") of the application. It has all the usual stuff such as pages, menus, administrators, contacts, access privileges etc. This module I put into every application and it works fine.

I use namespaces for all the classes in this module. For example the models are in the namespace \core\models. In this way I can easily extend them in the application while keeping the module "core" the same on all applications. I just do a class User extends core\models\User and everything works just fine. The controllers do not use the models in core\models, they are actually using models in the main application. Even the controllers in the core do not use the core models, they always go through the application.

This means that I end up with something like this.

I also have the base model as a component in the core module. So in my application


class Model extends \core\components\Model



In my core:


namespace core\models;

class User extends \Model



In my application again:


class User extends \core\models\User



In the end I end up with the class \User(app) extends \core\models\User(core) extends \Model(app) extends \core\components\Model(core)

This does give me a lot of flexibility, as I can modify either \Model to change the behaviors of all the models in the entire application including my core, and I can modify \Menu to change the Menu model in both my application and my core.

Is there a better way to do this?

I have tried the class mapping mechanism like it is described here would this allow me not to have so many extends?

I actually have to change a lot to make this happen and I am thinking before starting on this road there might be something I am missing.

I am thinking maybe defining something in the config that can act like Yii does with components that will get picked up and run automatically? Like is is replacing on runtime "clientScript" with another class, could I just not define my Model class in my application and have everything use my \core\components\Model right away until I define something in the config? (IOC logic from my understanding)

PS: sorry for the wall of text :(.

Don’t panic. It’s all ok. It’s a good habit to subclass and Yii help you to have this habit.

It is not a big bother for me, i just have to create 1 almost empty file all the time, and I know there is no performance problem with it, just wondering if there is a better way.