Organise Yii models into subdirectories

Swapnil
1 Comment

The default convention in Yii is to group all the models into a single folder which is Model i.e yii app => protected => models but when your app is large the database tables are also large and handling all these models inside the root folder is difficult, other principle of MVC architecture says you should have every Model : a ViewModel precisely for your associated View even a partial view hence as the number of models grows organise your code into subdirectories and import all the folders in the main controller from which your app controllers are derived or in every controller do this inside Controller’s init method.

One Response to “Organise Yii models into subdirectories”

  1. Niclane says:

    Before calling import static method it’s better to call parent::init(); method.

Leave a Reply

Search

Powered by Ajaxy