O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required