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 Room
model in common/models
:
<?php namespace common\models; class Room extends ActiveRecord { …. …. }
In the backend application, we will create an empty extension to the Room
class from common namespace:
<?php namespace backend\models; class Room...