Introduction to Model-Glue - MD ColdFusion User's Group
Download
Report
Transcript Introduction to Model-Glue - MD ColdFusion User's Group
Introduction to Model-Glue
Rachel Lehman
[email protected]
http://rmaxim.blogspot.com
Perpetual Intermediate Designer-Developer
Introduction to Model-Glue | Rachel Lehman
1
Model-Glue:ColdFusion
•
•
•
•
An MVC Framework for ColdFusion
Open Source
Also does scaffolding
Works well with other frameworks
(and uses them)
• Simple enough for beginners
• Powerful enough for enterprise development
Introduction to Model-Glue | Rachel Lehman
2
Agenda
•
•
•
•
•
•
•
•
What a Model-Glue application looks like
What the framework does
Installation & configuration
Hello World example
Master-Detail example
A few handy tips
Upcoming in Model-Glue 3
Q&A
Introduction to Model-Glue | Rachel Lehman
3
Basic Model-Glue Application Architecture
Model (CFC business objects & data access)
CFCs for business objects (Beans)
CFCs for data access (DAOs & Gateways)
CFCs for service abstraction (Service layer)
View (CFM display code)
CFM pages for view templates (dspIndex.cfm, dspTemplate.cfm, dspMyPage.cfm)
Common includes (headers, footers, UDF’s, etc)
Where the HTML goes
Controller (CFC business logic)
CFCs to connect your views to your model
Configuration (XML defining your application)
ColdSpring.xml defines ModelGlue application settings
ModelGlue.xml defines the pages (events) in your application
ORM Configuration: Reactor and Transfer (required for scaffolding)
Application.cfm (soon to be Application.cfc, defines app name)
Index.cfm (front controller, imports framework, all requests go through here)
Introduction to Model-Glue | Rachel Lehman
4
Model-Glue Event Flow
Introduction to Model-Glue | Rachel Lehman
5
Installation
• Download MG from http://www.model-glue.com
• Download ColdSpring from
http://www.coldspringframework.org
• Download Reactor from http://www.alagad.com; or
Transfer from http://www.transfer-orm.com
• Unzip files and copy the framework files to your web
root, or what ColdFusion sees as /modelglue,
/coldspring, /reactor (with mappings if necessary)
• Copy the modelglueapplicationtemplate directory to
where you wish to deploy your application
Introduction to Model-Glue | Rachel Lehman
6
Configuration
• Open the build.xml file – ANT build file
• Edit the project name, application name, and
application directory
• Run the file as an ANT build (either through
Eclipse, or the command line with ANT)
Introduction to Model-Glue | Rachel Lehman
7
No Ant?
• Don’t be intimidated, it’s super simple and comes
with Eclipse (you have it if you’re using CFEclipse)
• You can also follow these steps for a manual
install:
– Create a new directory called "myappname" under your Web root.
– Copy the contents of the /modelglueapplicationtemplate directory to the /myappname
directory.
– Open /myappname/config/ColdSpring.xml
– Do a find and replace, changing "modelglueapplicationtemplate" to "myappname"
– Open /myappname/config/ModelGlue.xml
– Do a find and replace, changing "modelglueapplicationtemplate" to "myappname"
– Open /myappname/Application.cfm
– Do a find and replace, changing "modelglueapplicationtemplate" to "myappname"
Introduction to Model-Glue | Rachel Lehman
8
Here Goes Nothin!
• Browse to the home page of your application,
and you should see…
Introduction to Model-Glue | Rachel Lehman
9
What You Should Know About
Configuration (ColdSpring.xml)
• Reload (true for development, false for
production) & reload password (defaults to true)
• Rescaffold (true for development when using
scaffolding, false otherwise and for production)
• Debug (true for development, false for
production)
• Preferences, Names for common terms (default
event/page, event name, reload key, etc)
• Mappings to files (views, scaffolds, config, etc)
Introduction to Model-Glue | Rachel Lehman
10
Adding and running a new event
DEMO: HELLO WORLD
Introduction to Model-Glue | Rachel Lehman
11
A Few Tips
• Force application reload with init=true
• Get the current page and event name (base URL) with
viewState.getValue(‘myself’)
• Forward events within the Controller (like <cflocation> but within
the framework) with event.forward() for redirection
• It’s event within the Controller, and viewState within the views*
• Centralize application settings with GenericConfig beans
• Create multiple view templates for different layouts or types of
delivery (home, subpage, popup, rss, etc)
• Add an unnamed result to the xml and it will execute at the end of
the request for easy site-wide templates
• Lock down your config files (store outside the web root and use a
mapping, or apply directory security) and if possible, the framework
itself.
Introduction to Model-Glue | Rachel Lehman
12
An application put into practice with Model-Glue
DEMO: MASTER/DETAIL
APPLICATION (CF ART GALLERY)
Introduction to Model-Glue | Rachel Lehman
13
From Here…
• You can organize and divide your application
with multiple
– Controllers
– ModelGlue.xml config files
– ColdSpring.xml config files
• ActionPacks are pluggable Model-Glue
applications
• Check out Generic Database Messages and
Scaffolds features for quick admin interfaces
Introduction to Model-Glue | Rachel Lehman
14
Now in Alpha
Model-Glue: Gesture Feature Preview
• Event generation – type the name of an event that doesn’t exist,
and your stub XML, controller methods, views and even a unit test
case will be generated for you
• Custom-typed events allow you to bundle repetitive event
functionality (templates) into the event, rather than defining it with
each event handler in your xml
• Application.cfc support (CFMX6 has been EOL’d)
• All event values are now stored in the Event object, no need to use
viewState
• Easy ways to manage search engine safe URLs
• Helpers – for an easier way to include UDFs
• Dead-simple caching (in event xml – cache=true) – extendable for
you to implement on your own
• Estimated release is Mid 2008
Introduction to Model-Glue | Rachel Lehman
15
Resources and Further Reading
•
•
•
•
•
ModelGlue mailing list (Google Groups ID- model-glue)
Documentation: http://docs.model-glue.com/
Joe Rinehart’s Blog: the author of Model-Glue
http://www.firemoss.com/blog
Ray Camden’s Blog: intro series, answers to many FAQ’s:
http://www.coldfusionjedi.com/index.cfm/ModelGlue
Other Blogs that cover Model-Glue:
– Todd Sharp - http://cfsilence.com/blog/client/
– Doug Boude - http://www.dougboude.com/blog/
– Dan Wilson - http://www.nodans.com/
•
•
Model-Glue Cookbook: http://modelgluecookbook.com/
Demo applications written with Model-Glue:
– Canvas wiki: http://canvas.riaforge.org/
– Litepost blog: http://code.google.com/p/litepost/
– Sample apps with MG install
•
•
Apache ANT for deployment - http://ant.apache.org/
I’ll post my code examples on my own blog at http://rmaxim.blogspot.com
Introduction to Model-Glue | Rachel Lehman
16
Thank you!
Q&A
Introduction to Model-Glue | Rachel Lehman
17