1. Is this the only way for external shared models?
2. MySample.cfc has an init() with a required argument. Is the
getModel('MySample').init("getMySampleInfo()") a correct syntax?
Thanks for your prompt response.
The MySample.cfc is outside of the convention “model” directory,that
is why i did addModelMapping(path="/common/models/MySample"); but the
problem is that an error is thrwon on passing param into the init()...
I am trying to found if CB can have an external model directory? I am
still learning about the DI and model autowiring stuff, and I should
not have any autowiring in the application or at least don't intent
to. Indeed, this is a very simple testing application for my learning
purpose(I tried CB sometime ago, and now come back to see if I can
grasp it better… =); it has only one handler, one ample cfc…
This is mapping the location, and is why I suggested removing the path back
to its roots. I am aware that error is telling you that it is not passing
something in, and I am thinking that somewhere you either have you bean.cfc
setup incorrectly or you hare trying to inject it somewhere.
If you are using property name='something' inject='model.mySample' this
doesn't pass anything into the init and will throw this error. And I am
almost 99.99% positive that this is the problem.
The templates have been used for testing and are kind of messy.
After I cleaned it up, and it seems work ok now on CreateObject
without using the getModel().init(), which is still not so clear to me
=)
Luis, "...when you call getModel(), this calls automatically the
"init()" constructor." but how we can pass a value if the init() has a
required param?
And if you don't mind i would like to ask you two more questions. I
like it much all the CB tools and flexibility, but not sure
1. if the CB application starting time can be reduced in a production
environment? (it takes too long to reinitialize framework every time
even with a very simple event)
2. not planning to have the stuff such as Dependency Injection,
autowiring and etc, but all those related functions/coding will be
still running. Do you think that will drag down the performance of the
CB application? can those features be bypassed or disabled.
In production you would have a different set of config settings, usually to
cache things somewhat. To give you an idea on my machine at home with debug
and no caching I can render a page in about 5-10 secs (Due to the large
amount of structs in rc) But as soon as it goes to production I am running
in around 200ms-500ms depending on the page.
The templates have been used for testing and are kind of messy.
After I cleaned it up, and it seems work ok now on CreateObject without
using the getModel().init(), which is still not so clear to me
=)
Luis, "...when you call getModel(), this calls automatically the "init()"
constructor." but how we can pass a value if the init() has a required
param?
And if you don't mind i would like to ask you two more questions. I like
it
much all the CB tools and flexibility, but not sure
1. if the CB application starting time can be reduced in a production
environment? (it takes too long to reinitialize framework every time even
with a very simple event)
2. not planning to have the stuff such as Dependency Injection, autowiring
and etc, but all those related functions/coding will be still running. Do
and Luis, i may be slow on this but i am still trying to figure out
how getModel() work...
you said "...when you call getModel(), this calls automatically the
"init()" constructor." my question is if a required param can be taken
by the init() ?
i am reading the CB BeanFactory.cfc, and if i am not wrong here is the
block of the code to handle the getModel(). and from what i read so
far, an obj will be init()ed but without taking in any params. am i
missing anything here?
...
// Create the model object
oModel = createObject("component", modelClassPath);
//If we are to execute the init() constructor, then do it.
if ( arguments.executeInit ) {
// Verify Constructor: Init() and execute
if( structKeyExists(oModel,"init") ){
try{
oModel.init(argumentCollection=getConstructorArguments(oModel));
}
catch(Any e){
....
Here, you can see that getModel supports an argument called initArguments. It’s a struct, and looks like more or less of a passthrough to the constructor. The original issue you are facing with getModel().init(‘foo’) is that the error is thrown inside getModel - with its own init call - before you ever get to your own .init(‘foo’) call. Note: haven’t actually tried this yet, but it looks like that’s what initArguments is there for.