Readers of my blog know that I am a huge fan of the Model-Glue framework. While I certainly don't consider myself an expert, I thought folks might appreciate a simple walk through building a real Model-Glue application. With that in mind, I'm starting a new series today. In this series I'll design a Model-Glue application and share the complete code as each step is built. I will also host the application online so my readers can see it in action (and see it as we build it up). One quick reminder before we start. I'm a Model-Glue newbie. I love it and I want the world to appreciate it, but do know that I'll probably make a few mistakes along the way. Those of you more advanced then I, feel free to chime in, or even just to point out alternatives. So with that out of the way, let's get started.
My assumption is that if you are reading this, you already have an idea what Model-Glue is. In case you don't, let me commit a quick round of copyright theft and quote from the Model-Glue Quick Start (And by the way, the quickstart on the web site is actually a little bit older. You should consult the quick start from the Model-Glue download):
There's been a lot of talk about using ColdFusion Components (CFCs) to seperate presentation layer from business logic. Model-Glue facilitates this by giving you an easier, more powerful way to connect your presentation layer (View) from your business logic (Model). It does this by letting you create what are called "Controllers", and then letting you define how they interact with the presentation layer (We're calling it View from now on!) through a simple XML schema.
That really doesn't do it justice, but hopefully it gives you an inkling about the power of Model-Glue. With that in mind, let's talk a bit about the application we are building. I've never been a huge fan of Flickr, but a friend kind of convinced me to take a second look. I have to admit I like how easy it is, especially the Windows client that let's you drag and drop pictures to upload. All was going great until I discovered a little problem. While I like that you can tag your photos to be private, the only way that your friends can view the pictures is if they register as well. What I was hoping for was either a simple password or a unique URL to share with family.
- Our application will attempt to solve this. It will have the following features:A user can register for the site.
- A user can logon with a username and password. (Once they have registered of course.)
- A user can create, edit, and delete galleries. Galleries are nothing more than folders with nice names.
- A user can upload photos to galleries. A user can delete the photos as well. To keep things simple, we won't worry about captions or photo metadata or anything like that.
- A user can view a gallery as a slide show, a slide show being nothing more than an HTML display of each photo with links to the previous and next image.
- Last but not least, the user can create a guest password. A guest password lets someone view your photos.
So, I had hope this would be a bit simpler, but as I typed it out, like most things, it got more complex. However, we will take things slowly, and build out the application in steps. With that in mind, let's tackle the very beginning of this application by first downloading the Model-Glue framework. You can download the code here. Once downloaded, you should follow the Quick Start instructions in the zip to install the framework. I'd also recommend creating a new virtual server to run the code. If that sounded like Greek to you, I highly recommend reading the ACME Guide by Stephen Collins. He takes you through the process of installing Apache and creating virtual servers.
Assuming you have the server set up, and the Model-Glue zip downloaded, you will find a "modelglueapplicationtemplate" folder. This is a skeleton Model-Glue application that you can use as the basis of any new Model-Glue application.
The first thing you want to do is... edit the Application name in the Application.cfm file. I only mention this as I forgot to do so, and went crazy trying to debug an issue with this. The Application.cfm file should look like so (I've added line breaks to make it readable here):
<cfsilent>
<cfapplication name="ModelGlueApplicationTemplate" sessionmanagement="true"/>
</cfsilent>
Change the name to "PhotoGallery" and your code will look like so:
<cfsilent>
<cfapplication name="PhotoGallery" sessionmanagement="true"/>
</cfsilent>
To be fair, this is mentioned in the Quick Start, but I must have been a bit lazy that day. Next we need to configure the ModelGlue.xml file found in the config folder. This is the main file that will control just about everything in the application. We need to edit three lines in it. The lines are below:
(from the <config> block)
<setting name="beanMappings" value="/modelglueapplicationtemplate/config/beans/" />
<setting name="viewMappings" value="/modelglueapplicationtemplate/views" />
(and from the <controllers> block)
<controller name="myController" type="modelglueapplicationtemplate.controller.Controller">
The Quick Start guide recommends simply rewriting "modelglueapplicationtemplate" with the name of your application. But this only works if you have a ColdFusion mapping or are creating a folder under web root. In our case, our Model-Glue application is at web root. So we will modify the three lines above to look like so:
<setting name="beanMappings" value="/config/beans/" />
<setting name="viewMappings" value="/views" />
<controller name="myController" type="controller.Controller">
Still with me? If you open up your application (mine runs at dev.photogallery.com), you should see the default Model-Glue home page. You can see this here.
That's it for today. The next entry will discuss how we can apply security to our application so a user is forced to logon or register.
Archived Comments
This is absolutely awesome! Thanks for taking the time to do this. Homework for me tonight.
Ray,
What a great idea! As I said on my blog, you're putting most other CF developers to shame :-) Quick question--are you planning on using Reactor with this application or using hand-built data access?
Mark
I am NOT planning on using Reactor. Why? I haven't learned it yet. I've looked into it, and it looks to be -very- awesome, but since I haven't build a site with it yet, it would be hard for me to discuss it. ;) When I do get around to learning it, I will though.
Great stuff. It's really helpful to see how other people go about building applications.
I'm excited about this series! :-) Can't wait for the next installment.
Ray, aweseome post. I am in the middle of trying to get a few apps to work with MG and the blanks in my knowledge are the bits about what the beans do and how to implement security.
Keep it up!
MD
YES RAY!!!!! I know it's not much but I pre-ordered "PSP YS: The Ark of Napishtim" from your Amazon wishlist so you should receive it a few days after it's released... you might want to add a few more items to your wish list, it's looking a little thin. (and darn those XBox games are expensive!)
Part 2 and part 3 are partially written. However, it may be a few days since this week is pretty busy. Once past this week things calm down. Thanks for the feedback all.
first. loving the comments and comment section.
second. im stuck on the install :( as soon as my hosting company has my dns up, ill send ya tha url so you can maybe help me figure this out, i want to follow you on this trek.
Folks, I've attached the files for this version of the application. Sorry it took so long.
Mr. Camden,
I was pointed to your site by an friend who loves and uses Model-Glue.
I started working my way thru this initial tutorial and found the link for "You can see this here." appears to be broken at the moment and wanted to bring that to your attention.
Although I am just starting, I really enjoy your writing style, makes it easy for an absolute newby to start to understand this thing called Model-Glue. I have a long way to go, but thanks.
Doug Cranston
Looks like a DNS issue. I fixed it, but it may take a few hours to update.
Thank your for your quick answer..
I must apologize in my tardiness in responding. Went out of town and just returned to the office.
Again thank you.
Doug Cranston
Hi there, Im sorry to bother with this question, but Im just starting to use coldfusion and model-glue (latest version); I have been looking how to create a simple form (name, email, subject, comments, submit) fro my contact page. The form I have create it, but my problem is that I don't know hoe to pass the form values to the action page, the emails arrives with "blanks" not content.
Link
http://www.convencionesvall...
Can you help me to create just a simple contact form?
Thanks in advance
Felipe Serrano
Your form values are available in the viewState (if you are in a view) or the event argument if you are in a controller. Remember that MG will consolidate all your input (form, url) into one scope.
I currently have an application.cfc in which i have code for each of the functions inside this component, onrequeststart(), on applicationstart() etc. How can I integrate this into MG?
Thanks in advance.
Things like onAppStart really translate better into the init functions for your controllers, and as for settings, they are set in ColdSpring.xml and will be run once only. Things like onRequestStart also translate into controller methods as well.
up up
it do me a great help
Did what it says here but there's NO (from the <config> block)
<setting name="beanMappings" value="/modelglueapplicationtemplate/config/beans/" /> section in the ModelGlue.xml file
Check the docs at Model-Glue - this setting is probably deprecated now.