Sharing ActiveRecord models among applications

Although every folder in the main Yii project could be considered a Yii standalone application, with its own controllers, models, views, and so on, it is conventionally accepted that all shared data are located in the common folder.

So every shared model (such as User, Room, Reservation, and Customer) that could be used in other Yii applications, should be inserted in common/models, under the common\models namespace.

From my point of view, when an application needs to use an ActiveRecord from common/models, I rather prefer to point to an extended version in its namespace, so as to have a chance again to add custom methods or properties to model for that application.

For example, consider we have the ...

Get Yii2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.