Difference between #3 and #4 of
Alternative folder structure for a standard Yii app

Revision #4 has been created by Trejder on Apr 25, 2013, 11:43:38 AM with the memo:

Some small edits
« previous (#3)

Changes

Title unchanged

Alternative folder structure for a standard Yii app

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

code organisation, protected folder structure

Content changed

[...]
### `components` folder

In default Yii application, virtually _anything that looks similar to the component_ is kept all together in the `protected/components` folder. I found this less useful, so I proposed to separate this folder into four subfolders:

-
`behaviours` -- contains all the behaviours, - _`extenders_` -- all classes, that extends framework's base classes, for example `Controller`, - _`functions_` -- classes, that acts like common function repositories or helpers, - _`widgets_` -- for all the visual widgets. **Note: Some propose naming `functions` folder with better suiting `helpers` name.**
 
 
Changing structure this way, you have to also change small part of your app's configuration. I.e. change:
[...]
Similar change goes for models. Default Yii code organisation keeps all models together and distinguish form models from data models by adding `Form` into form models class name. That was something, that I didn't like from the very beginning, so I split `protected/models` folder structure into two subfolders:

-
_`data_` -- all data related models`, - _`form_` -- models for all forms.

Similar change to application's configuration must be taken here. Change:
[...]
There were some forum rummors a year or two ago, that putting layouts in the same structure level as all other controller-related views might be sometimes confusing. I fully agree with that. Situation gets even worse, if you're using widgets, that renders some views. So, to cleanup `protected/views` folder structure, I've separated it into three subfolders:

-
_`controllers_` -- moved all other views' folder here, - _`layouts_` -- remains untouched, as in original, auto-generated app, - _`widgets_` -- views for possible widgets.

Views that are general or application-wide (for example `error.php`) are kept in original place, i.e. directly under `protected/views` folder, without further spearation to some folder. But, you may consider creating `general` subfolder and keep them there.

To make your application working with new `views` folder strucuture, this time you don't change nothing in app's config. Instead, you have to modify your base controller (`protected/components/Controller.php` in original Yii structure or `protected/components/extenders/Controller.php` in above presented), i.e. the one from which all your app's controllers extends from.
[...]
3 0
9 followers
Viewed: 21 612 times
Version: 1.1
Category: How-tos
Written by: Trejder
Last updated by: Trejder
Created on: Apr 12, 2013
Last updated: 11 years ago
Update Article

Revisions

View all history