home *** CD-ROM | disk | FTP | other *** search
- <CFSET Title = "Under the Hood, Pt. 2">
- <CFINCLUDE TEMPLATE="_header.cfm">
-
- <h3>Under the Hood, Pt. II</h3>
- <P>So far, we've described explicit and implicit object calls in very abstract
- terms; now you'll see how it is actually implemented.</P>
- <P>Each type of object call is wrapped in a custom tag. Explicit calls are executed
- via <CODE><CF_ShowObject></CODE> and implicit calls are executed via
- <CODE><CF_ShowContent></CODE>.</P>
- <h4><CF_ShowObject></H4>
- <P><CODE><CF_ShowObject></CODE> is the simpler of the two tags because it
- only needs to render one object, and it already knows which object it wants. We
- start with a <CODE><CFQUERY></CODE> to fetch all of the object's content
- from the database.</P>
-
- <BLOCKQUOTE><PRE><CFQUERY DATASOURCE="CFexamples" NAME="GetContent">
- SELECT PubContent.*, PubContentTypes.*
- FROM PubContent, PubContentTypes
- WHERE PubContent.TypeID = PubContentTypes.TypeID
- AND ObjectID = #Attributes.ObjectID#
- </CFQUERY></PRE></BLOCKQUOTE>
-
- <P>This query gives us a recordset that looks something like this:</P>
-
- <TABLE BORDER="1" CELLPADDING="4" CELLSPACING="0">
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>ObjectID</B></FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Type</B></FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Data</B></FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Title</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"This Story's Title"</FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Teaser</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"Read this interesting article"</FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Body</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"The main story would go here."</FONT></TD>
- </TR>
- </TABLE>
-
-
- <P>Then, we create an associative array (or "struct") and put the content into it.
- As you will see, this makes the data far easier to work with later on.</P>
-
- <BLOCKQUOTE><PRE><CFSET Object = StructNew()>
- <CFLOOP QUERY="GetContent">
- <CFSET Temp = StructInsert(Object, TypeName, Data)>
- </CFLOOP>
- <CFSET Object.ObjectID = ObjectID></PRE></BLOCKQUOTE>
-
- <P>Now we have an associative array that looks like this:</P>
-
- <TABLE BORDER="1" CELLPADDING="4" CELLSPACING="0">
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Key</B></FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2"><B>Value</B></FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">ObjectID</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">132</FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Title</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"This Story's Title"</FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Teaser</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"Read this interesting article"</FONT></TD>
- </TR>
- <TR>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Body</FONT></TD>
- <TD><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">"The main story would go here."</FONT></TD>
- </TR>
- </TABLE>
-
- <P>With Object array in hand, we are ready to render the object to HTML. For the purposes
- of this example application, we have put the CFML that renders the object directly into
- the <CODE><CF_ShowObject></CODE> tag, so you'd have to edit the tag itself if you
- wanted to create multiple ways of viewing objects. (<CODE><CF_ShowContent></CODE> does
- a little of this; see that section to learn more.)</P>
-
- <BLOCKQUOTE><PRE><CFOUTPUT>
-
- <DIV CLASS="HeadlineFull">#Object.Headline#</DIV>
-
- <BR>
-
- <CFIF IsDefined("Object.Image")>
- <P><IMG SRC="binarydata/#Object.Image#">
- </CFIF>
-
- <CFIF IsDefined("Object.Body")><DIV CLASS="BodyFull">
- <CFIF IsDefined("Object.InlineImage")>
- <IMG SRC="binarydata/#Object.InlineImage#" ALIGN="LEFT" HSPACE="10">
- </CFIF>
- #Object.Body#</DIV>
- </CFIF>
-
- <BR>
-
- <CFIF IsDefined("Object.HREF")>
- <DIV CLASS="LinkFull"><B>Go to:</B> <A HREF="#Object.HREF#">#Object.HREF#</A><BR></DIV>
- </CFIF>
- <CFIF IsDefined("Object.File")>
- <DIV CLASS="LinkFull"><B>Download:</B> <A HREF="binarydata/#Replace(Replace(URLEncodedFormat(Object.File),"%2E",".","ALL"),"+","%20","ALL")#">#Object.File#</A><BR></DIV>
- </CFIF>
-
- <!--- If browser is in Admin mode, display editing icons --->
- <CFIF IsDefined("Cookie.PubAdminMode")>
- <BR><A HREF="admin/properties.cfm?ObjectID=#ObjectID#"><IMG SRC="open.gif" WIDTH=16 HEIGHT=14 BORDER=0 ALT="Open" ALIGN="TOP"></A>
- <A HREF="admin/deleteobject.cfm?ObjectID=#ObjectID#"><IMG SRC="delete.gif" WIDTH=15 HEIGHT=16 BORDER=0 ALT="Delete" ALIGN="TOP"></A>
- </CFIF>
-
- </CFOUTPUT></PRE></BLOCKQUOTE>
-
- <CFSET HREF = "5-under2b.cfm">
- <CFSET Link = "Under the Hood, Pt. 2 Continued">
- <CFINCLUDE TEMPLATE="_footer.cfm">