Link to home
Start Free TrialLog in
Avatar of roger v
roger vFlag for United States of America

asked on

Coldfusion MVC or Fusebox - which one?

Hi,

I've got an existing coldfusion 9 application that was put together rather haphazardly without any MVC methodology or architecture. Now I've been tasked with re-engineering the entire application so it follows more the MVC pattern with index.cfm acting as the controller.

I've never used Fusebox or any framework before so I'm unsure on how to proceed. Would it be easier for me and also make more sense to re-engineer everything into a framework(fusebox, coldbox) or keep it simple and use index.cfm as the file that routes all the requests appropriateley?

Are there any easy to follow examples for this?
Avatar of gdemaria
gdemaria
Flag of United States of America image

Hey Roger, this is a question that is highly subjective to individual and personal preferences and experiences.  All I can do is share my opinion without saying it's the best.   I have used several different frameworks and ultimately found them to be all more work than they are good for.   When you create a page, the chances are that the query you use on the page has limited share-ability (to make up a word).   The select statement should select only the columns you need for that page and have a where-clause that is specific to the needs of that page.   Putting this select statement anywhere else besides the page is just an annoyance IMHO.   But I have seen the smallest, simplest queries inside subfolders, inside cfc files and then... guess what!   Three pages share the overly generic query and now one page has to do something different.  So, a new function in the cfc has to be written to add a join and the one page has to point to the new function...  Queries are made too generic to fit the framework and sharing just becomes a problem.  The exception is, of course, if you have a select that populate a SELECT or other common items such as categories, types, etc.  that have real reusability.   These, I put into a CFC and share them.

Same concept with the actions for a page.  Most of the time, the action for the page will be only used by that page.   I put this at the top of the page and then submit the page to itself.  How easy is that to have all available actions right at the top of a page and the selects for the page there too!   Developers heaven really...   Of course there are exceptions, if the actions are long or have real re-useability, they go into a seperate file and are cfincluded on the page.

Where do the queries and actions go that are external?  Just create a couple folders under each folder for them "actions" and "queries" or whatever mcv type name you want to use.  

Here's one huge benefit for this approach and a test I use for any framework - scenario.  The user populates a form page and submits the form.  There is an error, so you redraw the same page but you must make sure that all the entries the user made are still in-tact... without making the user click the back button!    I would not use any framework that didn't have this basic, but complex feature.   A page posting to itself can do this...

You can also still use the index.cfm file as the navigator, that's not a problem for this approach.

So that's one thing to consider, I think the hyper simplicity of this is a great selling feature as any developer can walk into the shop and understand what to do... no learning curve!    You just have to have some standards are folders... create a folder for each topic area "products", customers, orders, etc, etc...

Now, let the games begin...
Avatar of roger v

ASKER

Ah gde, this is exactly what i wanted! :)

I kinda understand what you're saying. The way the architecture is set up right now is sequential - one page takes user input, processes it in an action page that is included at the top. then the user moves to the next page which repeats the same process all over again. Right now the application is built for all high schools. The next step is for middle and elementary schools. The pages and the fields in those pages are similar but not same. So I need a way to distinguish at the very begining if it is a hight school, middle school, or elementarty school and appropriately route that request.

Let me ask you this - would I be better server by building a router cfc that takes the request and directs it to the apporpriate page?
MVC is an Architechure which is associated with Framworks (ColdBox, FuseBox) and brings OOPS concepts which are recomended in coding, but there is a lot of overhead in configuration and understanding of the Framework which implement it.

Building your own framework based on MVC is always easy, just basic thing is that you should separate out your business logic from your display logic, basically,

Model - Business logic
View - Display Logic
Controller - communication between Model and View..

would I be better server by building a router cfc that takes the request and directs it to the apporpriate page?  -- Yes, the router will act as a controller ....
> Let me ask you this - would I be better server by building a router cfc that takes the request and directs it to the apporpriate page?

First, I want to be sure I understand what you're referring to.. you are suggesting a central file that is always called that then cfincludes the correct template to process?   Typically I see this as the index.cfm file... not sure how it would work as a cfc... I typically don't like putting cfinclude files inside of a cfc, maybe that's because I have a cfc library and I don't want to files from my folder structure into my library.

I see the options as either...

1) mysite.com/index.cfm?page=studentList
     - with this method your index.cfm file can handle any common processing such as checking logins, attaching a side-bar menu, etc.  The downside is that the URL is less friendly and you need to be sure to carry the page variable around.
or

2) mysite.com/studentList.cfm
    - with this method, I always tend to put a cfinclude at the top of each file that includes something like "init_section.cfm"  or  "setup_page.cfm"  (something like that).   In this shared file I check logins, attach side-bar menu, etc.   Since it's called from the page, you can even do things like define the Page title, keywords, individual security levels for login and such.    <cfmodule template="setupPage.cfm" title="My Profile" role="user,admin" loginRequired="Yes">

So either way you can centralize processing within a folder.   It may come down to how friendly you need the URL to be and whether SEO is important.  

For a school site, I would want a very friendly URL but don't care about SEO as much because you have a captured audience :)

I may opt for the 2nd option.

By the way, I do a bunch of coding for the schools and have always dreamed of building a centralized homework site for our system... curious about your project?

Oh and speaking of different fields for different school levels - if you are just talking about a handful, then I would try using the same page and just hiding or showing fields based on the school level - which would be a global (request scope) variable.

The action could just default these variables so if they are not passed to the action (because they are hidden on the form) they simply update to NULL (unless that's not desired, then just CFIF them out of the update)


Avatar of roger v

ASKER

"By the way, I do a bunch of coding for the schools and have always dreamed of building a centralized homework site for our system... curious about your project?"

Yeah GDE, I've got high, middle, elementary schools and then special campuses like alternative campuses and so on. My application collects data for each campus that is then submitted to the state by which federal funds are allocated. Logically I've got the high, middle, elementary and special campuses segregation. I completed the high school part of the app and now gearing up for middle school piece. Which is why I need to re-engineer my existing app so based on what is being passed in (high school, middle school, etc), the appropriate page is displayed.

I'm still a lil fuzzy on the whole concept of the index as the controller but hopefully once I dive in, it'll become more vivid and use your awesome guidlines along the way! :)
Basically, the index.cfm page would look something like this...

<cfparam name="url.page" default="">

  Check security
  Setup Menu.

<cfif len(url.page)>
    <cfinclude template="#url.page#.cfm">
<cfelse>
    Page is not defined..
</cfif>


And it would be called using   mysite.com/index.cfm?page=profile

which would open profile.cfm


Personally, I kinda like the other option a bit more... where at the top of each page, you include a shared file.   That way you get to define page specific stuff like the page title, desription, security, etc...

Avatar of roger v

ASKER

OK so here is my current architecture:

My root folder:
*****************
\inetpub\wwwroot\ISD_DataCollApp

Files in root folder (\inetpub\wwwroot)
**********************************************
Application.cfc (this is where I define my session vars, my datasources and custError.cfm)
custError.cfm

Files in ISD_DataCollApp folder:
**************************************
index.cfm
disciplineInfo.cfm
specialEd.cfm
popAddAdmin.cfm
and some more files

Files that set a cookie and assign permissions:
************************************************************
\inetpub\wwwroot\includes\security.cfm
\inetpub\wwwroot\includes\header.cfm
\inetpub\wwwroot\includes\footer.cfm

Image files:
**************
\inetpub\wwwroot\images

Javascript files:
********************
\inetpub\wwwroot\scripts

CSS Styles files:
********************
\inetpub\wwwroot\styles

CFC files:
********************
\inetpub\wwwroot\cfc


As you can see it's a mish mash of everything. I've got index.cfm inside ISD_DataCollApp folder and then do cfinclude of the security.cfm and header.cfm and footer.cfm files. Do I need to move this index.cfm out of the current folder and put in \wwwroot? And how would that impact the IIS 7 setting? Currently I have it pointing to \inetpub\wwwroot\ ISD_DataCollApp\index.cfm from IIS.





ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial