Model Glue Tips Part 1: Separate out your Model-Glue file
Posted At : August 10, 2007 6:22 PM
| Posted By : Mark Drew
Related Categories:
model-glue
I have been developing a number of Model Glue applications over the last year and a half. Its a great framework and it has actually saved my neck on a project with incredible tight deadlines. I thought I would share some of the tips I have learned along the way by doing a series of posts with tips over the next couple of weeks.
In the first part of the series I shall be looking at:
Separate out your Model-Glue file
In any moderately sized project, you will start to gather a large number of controllers and event handlers, not to mention the messages you are passing back to the controllers. This will lead you to have a very large ModelGlue.xml file which becomes unwieldy and difficult to find things without the help of outline tools such as the CF Frameworks Explorer in Eclipse.
For this reason, I like splitting my my ModelGlue.xml file out into a number of files, this can be done easily thanks to the top level include tag (which is a child of the modelglue tag).
To use this, you simply have to create another ModelGlue file, and you simply point to it by doing the following:
< include template="config/ModelGlue_Pages.xml">
< include template="config/ModelGlue_Security.xml">
< include template="config/ModelGlue_Products.xml">
<controllers>
...
</controllers>
<event-handlers>
...
</event-handlers>
</modelglue>



My bad, I just put my layout in my main ModelGlue.xml and every include now recognizes my template event. Sorry hadn't noticed I removed it from my main config file.
cheers :-)
Is it possible to have multiple OnRequestStart methods in each separated xml/controller...?
example;
in my security xml file I would like an onRequestStart controller method that checked every requested event (security), for a isLoggedIn flag in the session, and in my admin.xml file I would like a controller method script to check against an isAdmin flag in the session...? If this is possible, would my event handler names be similar in both xml files??
cheers
and if this is possible which I'm assuming, which onRequestStart method takes precedence if they both get executed...?
Does this imply that each included file should start with <modelglue> and could/should contain the sections: event-handlers, views, etc; or is it more like a CF include - as long as the file contains valid XML that you could drop into ModelGlue.xml in place of the <include> then it will work? I can see advantages and disadvantages to both, but it certainly sounds like an idea that will be useful to me, and I'm not even done writing my <em>first</em> Model-Glue project yet. :)
Good look with the project!
How?
I have just been sketching out some ideas on how to implement this kind of thing on a huge project I am embarking on. As it's pretty massive I was wondering whether it might be worth subdividing the config's into seperate
folders. E.G:
config/users/usersmain.xml
config/users/usersadmin.xml
etc.
This way it's possible to really seperate out the various sections of the site into really manageable chunks.
I was also thinking of using the <include> tag in the various main sub configs. So I'd have an include to usersadmin.xml in the usersmain.xml file.
I haven't done any testing on this yet, but would be interested in comments.. I think on a big project, the smaller the config files can be and the more segmented the controllers are the better.
I tend to name my files something like modelglue_subsection.xml simply so I know what the XML file is from looking at the name, usersmain.xml might not tell you too much if you also have a coldspring file for the user configuration beans for example
Would you advocate the user of subfolders in config?
I was thinking it might be a nice way to seperate everything out as I can see the config directory growing quite fast.
Also, would you tend to <include> everything in the modelglue.xml or seperate these out into the various sub-config files (on a large site)?