itb2015 - migrating legacy applications to coldbox mvc

18
ColdBox <3 Legacy App IMPLICIT VIEW DISPATCH WRAPS YOUR APP IN COLDBOX

Upload: ortus-solutions-corp

Post on 22-Jul-2015

40 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: ITB2015 - Migrating legacy applications to ColdBox MVC

ColdBox <3 Legacy AppIMPLICIT VIEW DISPATCH WRAPS YOUR APP IN COLDBOX

Page 2: ITB2015 - Migrating legacy applications to ColdBox MVC

Your Host‣ Scott Coldwell

‣ Developer at Computer Know How

‣ Houston, TX

‣ CF dev since 2006

‣ @scottcoldwell

Page 3: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Define Implicit View Dispatch

‣ Practical steps to port your legacy app

‣ A vision for moving forward after porting

What We’ll Learn

Page 4: ITB2015 - Migrating legacy applications to ColdBox MVC

Implicating a dispatched view…huh?‣ In ColdBox, if a view file exists, it can be called

without a handler

‣ The handler/event are implicitly created

‣ The view doesn’t need to know anything about ColdBox

‣ You could write an entire app with only views

Page 5: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ If you could write an entire app with only views, you can drop an existing

application into the views directory, and it would run*!

‣ * slight modifications may be necessary‡

‣ ‡ … are almost definitely necessary

‣ Good news: fairly straightforward

Drop in that legacy app!

Page 6: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Make URLs compatible (index.cfm)

‣ Deal with Application.cfc/cfm

‣ Routes

‣ cfincludes, createObject, etc

Overview of Must-Dos

Page 7: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Primary concern: index.cfm in ColdBox URLs

‣ ColdBox has URLs like this out of the box: ‣ http://myapp.com/index.cfm/user/account

‣ But your app probably had a URL such as: ‣ http://myapp.com/user/account.cfm

‣ NOTE: the .cfm extension is no longer necessary, but IS permitted

‣ To fix: Enable SES URL setting in CB; web server rewrite rules (see docs)

Must Do: URL Compatibility

Page 8: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Coldbox is now the Application.

‣ Settings, environment variables, and other magic must find a new home ‣ May I recommend ColdBox settings and environments?

‣ Datasources, mappings, etc can be moved to ColdBox’s Application.cfc

Must Do: Application.cfm/cfc

Page 9: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ ColdBox auto-generates (implicitly dispatches) handlers and routes for

most cases

‣ You need custom routes for 2+ deep directories ‣ addRoute(pattern="/ajax/tags/:action", handler="ajax/tags");

‣ Use CLI tools to get a list for you ‣ find with mindepth option

Must Do: Routes

Page 10: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Prepend all <cfinclude> template values with /?views/

‣ - <cfinclude template=“/widgets/top_nav.cfm”>

‣ + <cfinclude template=“/views/widgets/top_nav.cfm”>

‣ - myObj = createObject(“component”,”cfc.myCoolObject”);

‣ + myObj = createObject(“component”,”views.cfc.myCoolObject”);

Must Dos: cfincludes, createObject, etc

Page 11: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ CFC invocation: createobject ()-> getModel() ‣ WireBox

‣ Move settings and environmental settings to ColdBox.cfc

‣ Utilize Layouts ‣ Assign layouts to views in ColdBox.cfc ‣ empty layout

Overview of Should-Dos

Page 12: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Use getModel() instead of CreateObject() ‣ easy search/replace

‣ Use WireBox inside of model objects ‣ + <cfproperty name="myOldCFC" inject=“model:myOldCFC">

‣ - <cfset foobar = createObject("component","myOldCFC").doSomethingAwesome() />

‣ + <cfset foobar = myOldCFC.doSomethingAwesome() />

‣ Consider how to handle the init() call, if applicable

Should Do: CFC invocation

Page 13: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ ColdBox has great settings management

‣ ColdBox has great environment management

‣ Use them

‣ Search/replace ‣ - application.mySpecialSetting

‣ + getSetting(“mySpecialSetting”)

Should Do: Settings, environments

Page 14: ITB2015 - Migrating legacy applications to ColdBox MVC

Should Do: Layouts‣ See if it makes sense for your app

‣ Control multiple layouts via Coldbox.cfc

‣ Special cases

‣ Blank layout for ajax responses

Page 15: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Move static assets to /includes

‣ Move CFCs to /models

‣ Utilize Security interceptor

‣ Configure WireBox for models

‣ Use RC scope instead of form/url

Overview of Could-Dos

Page 16: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ New development can be ColdBoxy

‣ Refactor legacy code to be MVC using models, handlers, and views

‣ Tighter integration with ColdBox offerings: (e.g. LogBox, ForgeBox items,

etc)

Going forward

Page 17: ITB2015 - Migrating legacy applications to ColdBox MVC

‣ Lay as much groundwork as you can, but get it out the door

‣ Search and replace (with regex) is your friend!

‣ Use a build process, not just source control

‣ Don’t take on too much at once! Port the app, then refactor

Final Notes

Page 18: ITB2015 - Migrating legacy applications to ColdBox MVC

ColdBox all the things