SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2007
    Posts
    402
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using CFS,Custom Tags and/or UDFs

    I am just recoding my whole site and am trying to do it in a more professional manner, so am clearing out all the cfqueries on each individual page, and was initially looking to replace them with CFCs.

    However, when reading Fortas WACK book today I have practised with UDFS and Custom Tags..

    The thing is, im not sure which techniques to use when and where....I would presume I could just use CFCs and am not sure where I would need to create my own UDFS and custom tags.

    Just wondering how other people managed their coding, and if they had any sample coding examples of how they have used various techniques together..

    Cheers
    discover song meanings and more http://www.music-explained.com

  2. #2
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Forta knows a thing (or 2 million) about ColdFusion, and I've just recently taken to reading his CFWACK 8 triad of books to get more advanced ideas about how to do such things.

    The way I do mine is I create an object and place it in the REQUEST scope, like this

    <cfset REQUEST.objDAO = CreateObject( "component", "path.to.dao.cfc" ) />

    In my dao (data access object, btw) cfc I have a function called runQuery that accepts SQL as well as DSN and other data.

    Now I can do this in any page:

    <cfsavecontent var="strMySQLToRun">
    SELECT *
    FROM TableName
    WHERE Condition=Value
    </cfsavecontent>

    <cfset qryResults = REQUEST.objDAO.runQuery( VARIABLES.strMySQLToRun, 'dsn_name' ) />

    And now qryResults will be created which has the results. I can reference qryResults whenever I want from that point til request end without making another database call.

  3. #3
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You could take the above 1 step further and have an object that dynamically pulls your SQL into the VARIABLES.strMySQLToRun variable. That way you can have all your SQL in 1 file, rather than spread out throughout your application.

    This is up to you. I've come to find that developers are as creative with their coding habits as designers when it comes to how their frameworks work. CF is modular enough to allow for a lot of different methods - developers are forever stuck trying to optimize which methods are best. The pursuit of perfection.

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2007
    Posts
    402
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just trying to fully grasp what your saying above..

    Im not 100&#37; about this bit...

    <cfset qryResults = REQUEST.objDAO.runQuery( VARIABLES.strMySQLToRun, 'dsn_name' ) />

    you are creating a cfset called qryResults that equals the info from the runQuery function in the cfc...but what does the (VARIABLES.strMSQLToRUn,'dsn_name') bit do?

    I presume its using the output of the <cfsavecontent var="strMySQLToRun"> to select info or something?

    Cheers
    discover song meanings and more http://www.music-explained.com

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2007
    Posts
    402
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aaron.martone View Post
    You could take the above 1 step further and have an object that dynamically pulls your SQL into the VARIABLES.strMySQLToRun variable. That way you can have all your SQL in 1 file, rather than spread out throughout your application.
    Yeah , this is what i would be aiming for, having all sql in one file..a bit like how i have all my css in one file...cheers

    Its interesting what your sayin, so much flexibility i suppose...
    discover song meanings and more http://www.music-explained.com

  6. #6
    SitePoint Addict Bloodfest's Avatar
    Join Date
    Feb 2006
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you look into MVC frameworks?

    You sound like me.. I'm very picky about the organization of my code.

    I've dabble around and worked up some simple frameworks on my own if your interested..

    it'll have you up and running in not time..

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2007
    Posts
    402
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    iv started with the coldbox framework now....its very very good!
    discover song meanings and more http://www.music-explained.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •