New Module Error

I just created a new module called blog and setup url rewrites. I want my main page to just be /blog so I dropped an index file in the root of views and changed the entry point of the application to “blog”. 2 questions

1.) Is there a default handler for / or should i just create a blog handler and do some kind of rewriting with urls
2.) the url http://localhost/hellocoldbox/blog/ is working but I am getting the following error

Message:
ERROR 09:03:55.524 PM Your app name here
Invalid Module Event Called: blog:.index. The module: blog is not valid. Valid Modules are: blog,forgebox

Dan,

I just asked the exact same question a few days ago, the entryPoint is not the default entry point in the way we thought.

That means the setting in the ColdBox config overrides this.

Not sure about your second question though.

Regards,

Andrew Scott

http://www.andyscott.id.au/

Ya I should of done what I always tell others to do RTFM ;0

I setup a route in the main app

addModuleRoutes(pattern="/blog",module=“blog”);

and then setup an ses route in my module

routes = [
{pattern="/", handler=“blog”, action=“index”}
];

now I can navigate to

http://localhost/myproject/blog and it loads correctly

Hmmm, that is interesting because I don’t think you need to do that. At least I never had to for my modules.

Regards,

Andrew Scott

http://www.andyscott.id.au/

so the entry point is not required according to the docs. I just created a security module called solitary

main app route

addModuleRoutes(pattern="/security",module=“Solitary”);

no default entry setup in my module config but some routes

routes = [
{pattern="/", handler=“security”,action=“index”},
{pattern="/login", handler=“security”,action=“login”},
{pattern="/logout", handler=“security”,action=“logout”}
];

maybe I am doing this all wrong, someone can tell me what I should be doing but this is working for me. I guess this is probably wrong though since its not very portable. You would have to add the route to your app. I will keep playing around.

All I did was create the myModule:myHandler.index and define the routes in the ModuleConfig.cfc, once you have done the wrapper created mentioned earlier. Then you will be able to use the module and be portable, does this make sense.

Regards,

Andrew Scott

http://www.andyscott.id.au/

Dan can you rephrase your question, I guess I am not understanding the issue. Sorry, kinda sick today.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Yes it does but what if you didn’t want people to access it from /mymodule…

that is why I needed the route setup in the main app

Don’t worry about it Louis, I am catching up here :wink: Though I do have another module related question.

Is there a way to turn on orm for the module? My module is going to use hibernate but your app may not so I want to set that up in my module.

Well that make sense then, but I was getting the impression that you wanted to be able to call it that way or did we miss read it?

Regards,

Andrew Scott

http://www.andyscott.id.au/

WOW, that’s a tough question, since the module is basically absorbed by the parent app which should have an Application.cfc already. I have thought about this and can just conceptually think out loud as I have not tried it.

I think an issue would be what if multiple modules have ORM enablement, I think that this should be controlled at the parent level because if not each module could potentially override the ORM settings of another module.

So I think the approach here would be to maybe enable the ORM at the parent app level and NOT specify a cfc location but let the entire packages be scanned in case more modules are dropped.

Thoughts?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Andrew, I never know what I am saying so you probably didn’t misread :slight_smile: I tend to blab a lot!

As far as the orm stuff goes I will talk this one through. I agree that this is probably a top level setting but lets just think about this.

I am creating a module called Solitary that will handle security for all of my apps. This module will look like this

+solitary

  • handlers
  • Security.cfc
  • model
    -BaseEntity.cfc
    +security
    -SecurityService.cfc
    +users
    -User.cfc
    -UserService.cfc
  • views
    +security

I was thinking of someway to create a nice drop in and go security module but the more and more I think about it I am not sure if I can do this because of all the setup I will need in the parent app.

1.) create a model route addModuleRoutes(pattern="/security",module=“Solitary”);
2.) enable orm
3.) would I have to setup the security interceptor in the parent app as well?

I don’t know, I am just talking out loud… not sure of how I can create something that we can just drop in and go.

  1. addModuleRoutes() is something you can do unless you use the module/handler/action conventions, but then you basically have all convention routes and not your own custom routes.
  2. The ORM enablement is tricky since it needs to flow from Application.cfc so that is more of getting tricky with CF
  3. you don’t have to setup the security interceptor in the parent app, you can do it in the module. The module interceptors work for the entire app not a module. So in all reality we are down to 1 and 2.

2 is something that maybe we can’t get around as that is how CF is built, plus all requests are going to the parent for routing.

Idea for 1) What if we added a small update where we actually put that this.entryPoint to use. What if by convention we use that this.entryPoint to call the addModuleRoutes() for you once a module is loaded. This can eliminate having to do the addition of where you want the module routes and just do it for you at the beginning?

This is very very easy to update and would give the entry point a better usage.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Dan,

I’ll talk about the ORM side in a minute.

With your Module I would take a little more interest in the on/un load of a module, I mention this because I have interceptors that are for the module only. And use something like this.

Function onLoad() {

controller.getInterceptorService().registerInterceptor(interceptorClass=interceptorClass, interceptorName=interceptorName);

}

This way you can add your interceptors, and of course use the unregister in the onload to remove them. I am sure that the addRoutes can also be done this way too.

I have also been thinking about the ORM side with modules as well, especially on the side of being portable and plug and play. The only catch is that no matter what the application has to be stopped and restarted for the ORM to take a hold of the changes, which got me thinking in a lot of different scenarios.

I try to keep eveything that is related together as much as possible, so if I can load a module up I would also like to try to keep the domains / entities in the module as well. Keeping in mind that I thought one could then copy the files around on unload/unregister, but I thought that would not be as efficent as it could be.

And this is still something that I am thinking about as well, and I think the best solution I can think of is something like this – psuedo code following.

onLoad() {

Register(ORMLocation);

}

onUnload() {

deRegister(ORMLocation);

}

These two methods could then create a file that can be loaded as xml, json or whatever tickles your fancy, that could also be used in the Application.cfc itself.

So you could say do something like this in the Application.cfc :

this.ormsettings.cfclocation = getORMLocations();

The idea is that the modules could then add/remove themselves from here, and these locations could then be loaded and used when the application has been restarted.

Now the only problem I had with this was that I wanted one model/service to handle the Module side, as well as the application.cfc side of things. Which is the bit I am trying to sortout now, but for now loading the object and calling the method could surfice. Just means if you move the file that you need to make sure you make this change in the Application.cfc

That was what I was thinking so far.

Regards,

Andrew Scott

http://www.andyscott.id.au/

How are you thinking with the call to addModuleRoutes? How flexible will this be?

Regards,

Andrew Scott

http://www.andyscott.id.au/

Look Below for answers:

I’ll talk about the ORM side in a minute.

With your Module I would take a little more interest in the on/un load of a module, I mention this because I have interceptors that are for the module only. And use something like this.

Function onLoad() {

controller.getInterceptorService().registerInterceptor(interceptorClass=interceptorClass, interceptorName=interceptorName);

}

This way you can add your interceptors, and of course use the unregister in the onload to remove them. I am sure that the addRoutes can also be done this way too.

You don’t have to do this, that is why the configure() method can do this for you:http://wiki.coldbox.org/wiki/Modules.cfm#The_configure()_method
Just do your interceptors = [] declaration and that’s it! You don’t need to specifically call the interceptor service.

Damn you Luis when did you put that in, I looked through the docs high and low when I did this for what could be used in the configure() and saw nothing for interceptors.

Well that just made my day now, can now remove some unwanted code.

Regards,

Andrew Scott

http://www.andyscott.id.au/

Awesome stuff guys! I think the ORM stuff is going to have to stay in the parent… let me read your comments again in the morning Andrew (I am beat).

I don’t think install notes for a module that go like this are all the bad

1.) drop /blog into the modules folder
2.) add the following orm settings to Application.cfc (or if they are already set, update) because remember we can have multiple datasources now!

I should also add that I did pull that from this bit of code, I was looking for a more generic way of just dropping interceptors into the application.

I was also looking at the MetaData of the component, to see if we could do the annotations, the properties would be the hardest though.

var interceptorPath = moduleMapping & ‘/interceptors’;

instance.interceptors = [];

//— Register Interceptors

var moduleRoot = expandPath(interceptorPath);

var files = DirectoryList(moduleRoot, false, “query”, “*.cfc”);

for(var count=1; count <= files.recordCount; count++) {

var interceptorName = listGetAt(files[‘name’][count], 1, ‘.’);

var interceptorClass = right(interceptorPath, len(interceptorPath)-1);

var interceptorClass = reReplace(interceptorClass & ‘/’ & interceptorName, ‘/’, ‘.’, ‘ALL’);

arrayAppend(instance.interceptors, interceptorName);

controller.getInterceptorService().registerInterceptor(interceptorClass=interceptorClass, interceptorName=interceptorName);

}

Regards,

Andrew Scott

http://www.andyscott.id.au/