Building a CF Library - PowerPoint PPT Presentation

About This Presentation
Title:

Building a CF Library

Description:

CFMODULE template='/mypath/mytemplatename.cfm' var1='string1' var2='string2' ... CF_MYTEMPLATE Var1='string1' var2='string2' Global modules ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 18
Provided by: dougl130
Category:

less

Transcript and Presenter's Notes

Title: Building a CF Library


1
Building a CF Library
  • What is a library, and advantages
  • Different types of CF libraries
  • When to use CF includes versus CF modules
  • How a ttTools library works, advantages over a CF
    module.

2
What is a code library
  • Pieces of code that are written once, used many
    times

3
Advantages of a library (Part 1)
  • Isolates code, so it is easer to re-use, both for
    the current project, and any future projects.
  • Isolates code and variables, so it is easier to
    debug
  • Make your own tool set that you are familiar
    with, improve and add to over time, and take
    with you as you move to your next job.
  • Make code that you can easily share with other
    programmers or resell
  • Categorize your code by TYPE/CLASS, in
    subdirectories

4
Advantages of a library (Part 2)
  • Make a tool set that your company uses for
    projects, help enforce a uniform, company wide
    programming style
  • Help ensure new programmers get up to speed
    faster with better code.
  • If a library function is used many times, a
    single change to the function makes a global
    change to the web site. This can be quite
    powerful.

5
Different kinds of CF libraries
  • CF Includes
  • CF Modules
  • Local Modules
  • Global Modules
  • ttTools Modules
  • CFX
  • CF Script

6
ltCFINCLUDE template/mypath/mytemplate.cfmgt
Includes (Part 1)
  • Is a an extension of the current page, the code
    is simply located somewhere else.
  • Any variables available to the page is available
    to the include
  • Easier to use since it does not require passing
    in formal parameters
  • Can easily cause programming errors due to
    undefined variables, or re-use of variable names
    that are the same as page variables!

7
How to Make CF Includes Library Friendly
  • Try not to use!, especially on large projects
  • Use CFPARAM for EVERY VARIABLE in the include
  • Try to name variables that will be unique to the
    include.
  • Only return a limited number of variables with
    special names.
  • Make a special directory for includes, with
    sub-directories by type or class

8
CF Modules
  • Accept defined INPUT parameters, know as
    attributes in CF
  • Can return variables (caller.variablename)
  • Cannot access page variables, so variables are
    isolated (this is a good thing!)
  • Can return page variables
  • Provide for some advanced CF features, such as
    child/dependant tags and open and close tags (not
    covered here)

9
CF Modules
  • CFMODULE tag
  • Global modules
  • CF_TEMPLATENAME Method
  • ttTools Method

10
CFMODULE tag
  • ltCFMODULE template/mypath/mytemplatename.cfm
    var1string1 var2string2gt
  • If it is a global tag, dont know where the tag
    actually is located, in case I want to edit it.

11
CF_TEMPLATENAME Method
  • ltCF_MYTEMPLATE Var1string1 var2string2gt

12
Global modules
  • Located in C\CFUSION\CUSTOMTAGS directory
  • Global tag names must be unique for the entire
    server
  • Sub directories of the CUSTOMTAGS directory can
    be used to categorize tags

13
How to Make CF MODULES Library Friendly
  • Dont use local modules!
  • Make a special directory for modules, separate
    from your pages
  • Document any variables returned using Caller.
    method

14
ttTools Method
  • A global module that calls local templates
  • Allows templates to be found locally and
    categorized
  • Allows for a global means of error handling and
    error logging
  • Allows for a global means of white space
    stripping
  • May allow for other global features I have not
    thought of

15
CFX (CF Executable)
  • Much harder to write
  • Usually purchased
  • Requires C programming (and programmer!)
  • Good for
  • writing functions that requires close integration
    with operating system
  • making a really fast web site
  • making code this is secure
  • making code that is hard to steal (ie, cannot be
    duplicated or put on another machine easily)

16
CF Script functions
  • Dont know much about this, but looks promising
  • Allows for formal CF functions, with both formal
    input AND output parameters.
  • Runs faster than regular CF code
  • Moves away from CF tag based programming, which
    was at the heart of why programmers love it

17
What makes a good Library tool?
  • Code is convenient to edit
  • Provides for formal input/output parameters
  • Can be organized by type/class
  • Easy to add Global Error Handling
  • Easy to add Global Error Logging
Write a Comment
User Comments (0)
About PowerShow.com