View Full Version : Auto loading Classes Using Organized Into Modules

14 Oct 2011, 10:48 AM
I am building quit a large application. The application essentially consists of 5 separate products. Therefore, instead of having a single model, view and controller directory I have several organized under a root level module directory.


- mod1
-- controllers
-- views
-- models
-- stores
- mod2
-- controllers
-- views
-- models
-- stores

I'm sure you get the idea.

The naming convention of my classes follows this pattern:

appname.[views | controllers | stores | models].[mod1 | mod2].NameOfClass

Any insight would be appreciated on overriding the auto loading functionality to support the above structure.


14 Oct 2011, 10:53 AM
The autoloader follows the directory structure. In your example if you would put mod1/mod2 folders inside of each view/controller/store/model folder it should do the trick.

14 Oct 2011, 10:57 AM
Well... I would really like to keep all module specific code under a single directory rather than separate it between multiple directories. That is why I was wondering how difficult it would be to override the implementation of the loader to support the structure I have. Even... where to start/look to achieve this goal.

Jacky Nguyen
14 Oct 2011, 9:42 PM
It's fairly simple to achieve what you want, just give Ext.Loader the proper mappings based on your structure. Here's how it may look like. Put these right above Ext.application(...)

'AppName.controller.mod1': 'path/to/src/mod1/controllers',
'AppName.view.mod1': 'path/to/src/mod1/views',
// ...
'AppName.controller.mod2': 'path/to/src/mod2/controllers'
// ... you get the idea

which makes every class under the 'AppName.controller.mod1.*' namespace being loaded from 'path/to/src/mod1/controllers/*', and so on. That solves the loading issue.

However, you may have some other issues with the current MVC code base since to be honest, we've never actually tried that custom structure. I'm not surprised if the custom class names are not respected in a few places. No worries, try that out and we'll help you along in this thread.

17 Oct 2011, 9:09 AM
please tell me how to disable the autoloader. I had already built my own autoloader which works well and I want to keep using it.

17 Oct 2011, 11:22 AM
ok so I decided to try and work with this.. I spent a lot of time programming my own autoloader but I figure yours must be more efficient.

So just so I understand right.. if I use your autoloader (which for now I have no choice since I don't know how to disable it), then this means that I don't have to manually link to my .js files? You will do all of that on your own?

Also.. I think I found a bug. I was having issues with your auto loader since my JS files are actually stored on a different subdomain than my html file.. luckily I was able to provide the absolute path using your

Ext.Loader.setPath({ ... });

code. However.. here's the funny thing. My "app" is named "app". I was only getting errors because your framework was trying to autoload my models.. so I gave it the absolute path using "app.models':

How come it didn't ask me to specify the paths to my stores and views?

Currently I AM loading ALL my .js files as I used to do before... so if I'm right and your framework is now autoloading some of my files.. then it means that some files are being loaded twice.

Would love some clarification here on whether I can stop loading up my js files manually.. (or some of them).

Also.. btw.. if you are loading my files manually than I just would like to let you know that this causes some complications since currently my own "autoloader" grabs ALL my js files and minifies them and combines them into ONE file for maximum caching and small filesize. If you are now autoloading my JS files then that means I will have to minify all my individual javascript which is quite a pain to do and much more time consuming when deploying new versions.

Anyway maybe I got this all wrong.. please let me know.

17 Oct 2011, 7:18 PM
Thanks for the information Jacky, it's appreciated. Though, sadly I've put this on hold going back to 1 because I am just running into way to many issues without the timeline to support them. thanks though… again.

19 Oct 2011, 8:20 AM
oddz, could you please be more specific as to what kind of issues you are running into?