Building your first Model-Glue application - The Final Battle
Ok, pardon the dramatic title. I guess I'm just happy to be wrapping this thing up. I loved writing it, but it certainly turned out to be more work than I thought it was going to be. To be honest, I'm not terribly surprised. If there is one thing I've learned in my years as a web developer, even the simplest project can turn out to be more complex than you (or the client) can imagine. I had hoped to cover a complete application, and I did, but I definitely cut a few corners towards the end. Sorry! I do hope that those of you who haven't looked into a framework yet will give Model-Glue a shot with your own development developments. So let me talk a bit about what I didn't cover, and what could have been improved.
Security
Those of you who read my blog regularly know that I'm a bit of a security nut, specifically when it comes to the proper checking of input variables. By that I mean form, url, cookie, and any value that is not directly controlled by your code. I find myself not being as anal as I normally would be. I think it's a visual problem. I'm so used to seeing URL, or FORM, and immediately thinking "Have I properly checked this variable?" Because Model-Glue abstracts this into the Event object (which is a good thing, don't get me wrong), I find myself forgetting to be as secure as I normally would be. Again - this is my fault and something I'll have to work as I write more Model-Glue applications. I point it out as I definitely noticed a few places I could have improved my checking in the PhotoGallery application.
Error Handling
Out of the box, Model-Glue will automatically fire an event, Exception, when an error occurs. One thing the PhotoGallery application needs is a nicer error handling template. Right now it just reports that an error has occurred. It would be trivial to add some simply code to email the exception to the owner. You can't assume your users will tell you about errors. (Shoot, I can tell you that I've sent hundreds of error reports to sites and only one in ten bother to write me back and thank me.) This is definitely not a Model-Glue suggestion, but a suggestion for all of your web sites. It takes about five minutes and can help you keep in touch with your web site.
Logging
One thing I tend to do a lot in my applications is logging. I probably would have added a lot more logging to this application if it were a real live production site. I'd log user creation, updates, new gallery, image uploading, etcetera.
While not exactly "logging", I would have used more metadata for my database tables. I mentioned this normally whenever I was describing a particular table. By metadata I simply mean a record of when a record was created and when it was last updated. I sometimes I also record the username of the user who last modified the record.
The End
Thank you to everyone who commented on the series and helped keep me on topic. Attached to entry is a zip that contains not only the source code (with a SQL Server database creation script), but also PDF copies of this entry and all the earlier articles. (To be honest, the zip will not contain this entry until about five minutes after I post - just in case your reading this entry immediately after I posted it.) If someone takes the photo gallery application and actually uses it, please let me know. Post the URL to this entry and share it with everyone else.
EDITED:
Emmet McGovern created an "uber" PDF that joins all the individual PDFs in one PDF. The zip still contains the individual PDFs as well. I did not update the file attached to this entry. In fact, I'm going to delete it. Please use the link in the right hand pod: http://www.coldfusionjedi.com/downloads/mgapp.zip
Comments
And also I used your code (with some changes to have it run with MySQL 4.1) to set up a gallery showing of the current renovation development of our "new" house.
If you are interested you can find it at: http://gallery.ulseth.no/index.cfm?event=viewgalle...
If I remember correctly, if you have Acrobat Pro, you can create a PDF from other PDFs.
http://ray.camdenfamily.com/downloads/mgapp.zip
Emmet graciously made an uber pdf, and thanks to everyone else who offered.
One thing that I'm not sure about is when I use MakeEventBean() it doesn't set the default value I have given in my cfargument. I have to explicitly call the set method. Any idea why?.
Can you show me how you are using makeEventBean? it won't take defaults from cfargument. It uses the event scope for data.
<cfset var bean = arguments.event.makeEventBean("clients_mg.model.userBean") /> and this is above all <cfif>s in the function.
My registration page has couple of fields that won't display unless the email domain is in a preapproved list. So I'm checking to see whether the field is displayed or not. If it is already displayed, then I go ahead and submit the form. If it is not displayed, then I check the email domain and display error or field accordingly. So I call
<cfif bean.getUserSite() eq ''> <!--- This checks whether the field is already displayed or not --->
In my userBean.cfc, I have a cfargument with default of 0. But my get method never returns 0 unless I explicitly call
<cfset bean.setuserSite()>
and then check <cfif bean.getUserSite() eq 0>
By the way, have you ever done a mvc framework from server standpoint?. Like having the presentation layer in one server and all your business logic in another server?. If so, can you share some of your suggestions or point me in the right direction?.
Is there by any chance an updated version of this application that uses ColdSpring for bean settings vs. the <config> block section in ModelGlue.xml that isn't really used anymore in version 2.0? I'm not certain how to add additional properties in my ColdSpring.xml file the same way you did with the additional <config> block settings (for DSN, admin email, etc) in the ModelGlue.xml file.
I started in on the ColdSpring documentation but was getting confused fast and thought, "I know ColdSpring really speeds up development from what I keep reading, but there must be a simple way to just add some basic application settings such as DSN, etc."
Any suggestions are greatly appreciated!
Thanks!!
Tony
<bean id="config" class="ModelGlue.Bean.CommonBeans.SimpleConfig">
<property name="config">
<map>
<entry key="dsn">
<value>foo</value>
</entry>
</map>
</property>
</bean>
You can imagine more settings in here as well. You can then pass this bean to a CFC:
<bean id="answerDAO" class="foo.model.dao.answerdao">
<constructor-arg name="config"><ref bean="config" /></constructor-arg>
</bean>
And in your CFC do:
<cffunction name="init" access="public" output="false" returnType="answerdao">
<cfargument name="config" type="any" required="true">
<cfset variables.dsn = arguments.config.getConfigSetting("dsn")>
<cfreturn this>
</cffunction>
- Tony

Again, thank you for doing this!