RE: [coldbox:10650] Model External

In general, you will need to create a ColdFusion mapping for any .cfm or .cfc files outside the webroot which are going to be cfinculded or instantiated from within your ColdFusion code. This includes views, handlers, models, interceptors, etc. I have three sites that share the majority of their code. Instead of creating a dozen mappings, we have a single mapping to a folder we named “common” which is outside out web root and we put all of our shared files in there. Then we reference everything as a directory or cfc path starting with “common” (the name of our mapping).

So, not on to your Models question:

Models are created by WireBox (unless you are using some other object factory). WireBox caches it’s own “mappings” to your cfcs which are defined in the binder config. Usually config/wirebox.cfc.

Let’s assume an example of a shared directory called “common” in which you have a models folder and inside that folder, a package (folder) called “user”, which contains a cfc called “userService.cfc”.
If you create a mapping called “common” that points to the “common” folder you would be able to resolve a full path to that cfc as “common.models.user.userService”

There are three ways WireBox can find your cfcs:

  1. scan locations - The default scan location is the models directory in your web root. Scan locations are NOT searched recursively. You need to supply the full relative package name when requesting a model from within a scan location. You can add as many scan locations you want-- including something to the effect of “common.models”. That would allow for the following in your code:
    wireBox.getInstance(“user.userService”)

  2. specific mappings - This is if you want to create a specific mapping in the binder for every single cfc to have exact control over how it is instantiated. You would specify the full cfc path e.g. map(“myUserService”).to(“common.models.user.userService”);
    wireBox.getInstance(“myUserService”);

  3. directory mappings - This tells WireBox to recursively scan an entire directory and map every CFC in it when the app starts up. (I use this) ex.
    mapDirectory(“common.models”)
    wireBox.getInstance(“userService”);

Now, as to which of those methods you use is entirely up to you. But that’s how they work, and they will all require a CF mapping to be able to find your external location where you’ve stored your models.

Let me know if that answers your question or not. (I wasn’t quite sure exactly what you were asking, so I answered broadly :slight_smile:

Thanks!

~Brad

Thank you Brad. I think I got it. Is there a way to do externalIncludes.What I want to do is since the layouts are external and Includes are external as well I do not see the styles are being apllied to the page