home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Examples / docs / pubdocs / 4-under2.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  5.9 KB  |  125 lines

  1. <CFSET Title = "Under the Hood, Pt. 2">
  2. <CFINCLUDE TEMPLATE="_header.cfm">
  3.  
  4. <h3>Under the Hood, Pt. II</h3>
  5. <P>So far, we've described explicit and implicit object calls in very abstract 
  6.   terms; now you'll see how it is actually implemented.</P>
  7. <P>Each type of object call is wrapped in a custom tag. Explicit calls are executed 
  8.   via <CODE><CF_ShowObject></CODE> and implicit calls are executed via 
  9.   <CODE><CF_ShowContent></CODE>.</P>
  10. <h4><CF_ShowObject></H4>
  11. <P><CODE><CF_ShowObject></CODE> is the simpler of the two tags because it
  12.   only needs to render one object, and it already knows which object it wants. We
  13.   start with a <CODE><CFQUERY></CODE> to fetch all of the object's content
  14.   from the database.</P>
  15.   
  16. <BLOCKQUOTE><PRE><CFQUERY DATASOURCE="CFexamples" NAME="GetContent">
  17. SELECT PubContent.*, PubContentTypes.*
  18. FROM PubContent, PubContentTypes
  19. WHERE PubContent.TypeID = PubContentTypes.TypeID
  20.     AND ObjectID = #Attributes.ObjectID#
  21. </CFQUERY></PRE></BLOCKQUOTE>
  22.  
  23. <P>This query gives us a recordset that looks something like this:</P>
  24.  
  25. <TABLE BORDER="1" CELLPADDING="4" CELLSPACING="0">
  26. <TR>
  27.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>ObjectID</B></FONT></TD>
  28.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Type</B></FONT></TD>
  29.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Data</B></FONT></TD>
  30. </TR>
  31. <TR>
  32.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
  33.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Title</FONT></TD>
  34.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"This Story's Title"</FONT></TD>
  35. </TR>
  36. <TR>
  37.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
  38.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Teaser</FONT></TD>
  39.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"Read this interesting article"</FONT></TD>
  40. </TR>
  41. <TR>
  42.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
  43.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Body</FONT></TD>
  44.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"The main story would go here."</FONT></TD>
  45. </TR>
  46. </TABLE>
  47.  
  48.  
  49. <P>Then, we create an associative array (or "struct") and put the content into it.
  50. As you will see, this makes the data far easier to work with later on.</P>
  51.  
  52. <BLOCKQUOTE><PRE><CFSET Object = StructNew()>
  53. <CFLOOP QUERY="GetContent">
  54.     <CFSET Temp = StructInsert(Object, TypeName, Data)>
  55. </CFLOOP>
  56. <CFSET Object.ObjectID = ObjectID></PRE></BLOCKQUOTE>
  57.  
  58. <P>Now we have an associative array that looks like this:</P>
  59.  
  60. <TABLE BORDER="1" CELLPADDING="4" CELLSPACING="0">
  61. <TR>
  62.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Key</B></FONT></TD>
  63.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Value</B></FONT></TD>
  64. </TR>
  65. <TR>
  66.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">ObjectID</FONT></TD>
  67.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
  68. </TR>
  69. <TR>
  70.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Title</FONT></TD>
  71.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"This Story's Title"</FONT></TD>
  72. </TR>
  73. <TR>
  74.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Teaser</FONT></TD>
  75.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"Read this interesting article"</FONT></TD>
  76. </TR>
  77. <TR>
  78.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Body</FONT></TD>
  79.     <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"The main story would go here."</FONT></TD>
  80. </TR>
  81. </TABLE>
  82.  
  83. <P>With Object array in hand, we are ready to render the object to HTML. For the purposes
  84. of this example application, we have put the CFML that renders the object directly into
  85. the <CODE><CF_ShowObject></CODE> tag, so you'd have to edit the tag itself if you
  86. wanted to create multiple ways of viewing objects. (<CODE><CF_ShowContent></CODE> does
  87. a little of this; see that section to learn more.)</P>
  88.  
  89. <BLOCKQUOTE><PRE><CFOUTPUT>
  90.  
  91.     <DIV CLASS="HeadlineFull">#Object.Headline#</DIV>
  92.  
  93.     &nbsp;<BR>
  94.  
  95.     <CFIF IsDefined("Object.Image")>
  96.         <P><IMG SRC="binarydata/#Object.Image#">
  97.     </CFIF>
  98.  
  99.     <CFIF IsDefined("Object.Body")><DIV CLASS="BodyFull">
  100.         <CFIF IsDefined("Object.InlineImage")>
  101.             <IMG SRC="binarydata/#Object.InlineImage#" ALIGN="LEFT" HSPACE="10">
  102.         </CFIF>
  103.         #Object.Body#</DIV>
  104.     </CFIF>
  105.  
  106.     &nbsp;<BR>
  107.  
  108.     <CFIF IsDefined("Object.HREF")>
  109.         <DIV CLASS="LinkFull"><B>Go to:</B> <A HREF="#Object.HREF#">#Object.HREF#</A><BR></DIV>
  110.     </CFIF>
  111.     <CFIF IsDefined("Object.File")>
  112.         <DIV CLASS="LinkFull"><B>Download:</B> <A HREF="binarydata/#Replace(Replace(URLEncodedFormat(Object.File),"%2E",".","ALL"),"+","%20","ALL")#">#Object.File#</A><BR></DIV>
  113.     </CFIF>
  114.  
  115.     <!--- If browser is in Admin mode, display editing icons --->
  116.     <CFIF IsDefined("Cookie.PubAdminMode")>
  117.         <BR><A HREF="admin/properties.cfm?ObjectID=#ObjectID#"><IMG SRC="open.gif" WIDTH=16 HEIGHT=14 BORDER=0 ALT="Open" ALIGN="TOP"></A>
  118.         <A HREF="admin/deleteobject.cfm?ObjectID=#ObjectID#"><IMG SRC="delete.gif" WIDTH=15 HEIGHT=16 BORDER=0 ALT="Delete" ALIGN="TOP"></A>
  119.     </CFIF>
  120.  
  121. </CFOUTPUT></PRE></BLOCKQUOTE>
  122.  
  123. <CFSET HREF = "5-under2b.cfm">
  124. <CFSET Link = "Under the Hood, Pt. 2 Continued">
  125. <CFINCLUDE TEMPLATE="_footer.cfm">