Skip to main content
Inspiring
October 29, 2008
Question

Best practice MVC for forms to cfc

  • October 29, 2008
  • 4 replies
  • 734 views
Conceptually I would like to keep my logic for a very big site as MVC as possible. As a cf newbie though I am not sure whether the strategy suggested by most of the blog/tutorials of sending (say)

index.cfm's Form.UserName to UsernameCheck.cfm which then <cfinvoke> Username.cfc

or if I can/should send Form.UserName directly to Username.cfc

Going direct is more straightforward obviously but then is the only place to put <cfif> (aka Controller) logic in the index.cfm page (which defeats my intentions anyway)????

I may be way missing something here, but fwiw I'm getting kind of spaghetti with multiple <cfelseif> 's for every index.cfm module so am presently leaning toward redirecting (say) failed signins to RetrySignIn.cfm rather than back to (essentially) a <cfelseif> of index.cfm.

Thanks in advance for feedback on your experiences, I realize this could be done/argued either way but . . .
    This topic has been closed for replies.

    4 replies

    Inspiring
    October 30, 2008
    There is so much that depends on one's situation. Mine is that I do intranet stuff for my employer. Most of the Cold Fusion work that I do involves select queries and presenting results.

    Most of the time, the db is our own data warehouse, which I help maintain. It could also be the db of a non-cf systme that we bought from a vendor. It could also be a db that I or one of my co-workers wrote.

    I do what I think is most appropriate for my circumstances. I can't advise you on yours.
    Inspiring
    October 30, 2008
    So then do you put into cfc's the <cfcatch> logic for if (say) the database is unavailable?
    Inspiring
    October 29, 2008
    fwiw I'm tending more to the latter (ie different RetrySignin.cfm page) at the moment
    Inspiring
    October 29, 2008
    cfc's are a way of re-using code or making cf code available to non-cf apps. If you are using them to for code re-use, then you have to design them that way. In other words, they have to be black boxes, independant of calling templates. This means your functions should be accepting arguments and this precludes submitting form data directly to the cfc.

    Inspiring
    October 29, 2008
    Yes, well stated. However, can/should I call cfcs directly from a form?
    Inspiring
    October 29, 2008
    quote:

    Originally posted by: ProjectedSurplus
    Yes, well stated. However, can/should I call cfcs directly from a form?

    You can.

    Whether or not you should is a matter of opinion. When I first came across a need to run the same code from more than one form, I made a .cfm file that all the forms called. Mind you, it wasn't a login page, I don't know what MVC is, and this was done not only pre-cfc, but pre-udf.