OK, I need a little help. I was asked, a few months back, to co-author a
book on Learning ExtJS. When I wrote my chapters, one of them required
server-side code, which I (of course) wrote in CF. Unfortunately, the
rest of the book's server-side examples are written in PHP. They asked
me to convert, but I don't know PHP, so they had the primary author
handle the conversion.
Well, apparently the author has less knowledge of CF than I do of PHP.
I've never studied or written PHP, but it's obvious that his conversions
won't work with the examples, and are not one-for one. One of my primary
examples had a cfc method that used cfdirectory to return a query object
of a directory's contents. He turned around and wrote something that
queried a MySQL db. He also returned the value in JSON format.
Unfortunately, that format doesn't mirror the format that ColdFusion
uses, which is actually a requirement of this exercise, as this piece of
the chapter explains custom data readers, and the example is reading
JSON in this (the CF) format to populate a data store.
Is there a PHP library that does something similar to what CF does, in
returning a query object for a directory structure? Can you create PHP
'classes', with methods that can be called directly in an Ajax call?
Here's the CFC I was using in my examples:
<!---
//
***************************************************************************************
// CLASS|TEMPLATE:
// Chapter_12\Chapter12Example.cfc
//
// PURPOSE:
// A ColdFusion component used for Ajax examples in Chapter 12
//
// AUTHOR:
// Stephen G. 'Cutter' Blades, Jr.
//
// CHANGE LOG:
//
***************************************************************************************
// SGB [07.17.08]
// Template created
//
***************************************************************************************
--->
<cfcomponent output="false">
<!---
/ METHOD: example2
/
/ @param id:numeric
/ @return output:string
--->
<cffunction name="example2" access="remote" output="false"
returntype="string">
<cfargument name="id" type="numeric" required="true" />
<cfset var output = "" />
<cfset var q = "" />
<cftry>
<cfquery name="q" datasource="chapter12">
SELECT firstName,
lastName,
occupation
FROM People
WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#ARGUMENTS.id#" />
</cfquery>
<cfcatch type="database">
<!--- Place Error Handling Here --->
</cfcatch>
</cftry>
<cfif IsDefined("q.recordcount") and q.recordcount>
<cfsavecontent variable="output"><cfoutput>
#q.firstName# #q.lastName#: #q.occupation#<br />
</cfoutput></cfsavecontent>
</cfif>
<cfreturn output />
</cffunction>
<!---
/ METHOD: getFileInfoByPath
/
/ @param startPath:string
/ @return q:query
--->
<cffunction name="getFileInfoByPath" access="remote" output="false"
returntype="query">
<cfargument name="startPath" required="true" type="string" />
<cfset var q = "" />
<cftry>
<cfdirectory action="list" name="q"
directory="#ExpandPath(ARGUMENTS.startPath)#" filter="*.jpg" />
<cfcatch type="any">
<!--- Place Error Handler Here --->
<cfset q = QueryNew('ID') />
<cfset q = QuerySetCell(q,'ID',0,1) />
</cfcatch>
</cftry>
<cfreturn q />
</cffunction>
<!---
/ METHOD: getDirectoryContents
/
/ @param startPath:string
/ @param recurse:boolean (optional)
/ @param fileFilter:string (optional)
/ @param dirFilter:string (optional - File|Dir)
/ @param sortField:string (optional -
NAME|SIZE|TYPE|DATELASTMODIFIED|ATTRIBUTES|MODE|DIRECTORY)
/ @param sortDirection:string (option - ASC|DESC [defaults
to ASC])
/ @return retQ:query
--->
<cffunction name="getDirectoryContents" access="remote"
output="false" returntype="query">
<cfargument name="startPath" required="true" type="string" />
<cfargument name="recurse" required="false" type="boolean"
default="false" />
<cfargument name="sortDirection" required="false" type="string"
default="ASC" />
<!--- Set some function local variables --->
<cfset var q = "" />
<cfset var retQ = "" />
<cfset var attrArgs = {} />
<cfset var ourDir = ExpandPath(ARGUMENTS.startPath) />
<!--- Create some lists of valid arguments --->
<cfset var filterList = "File,Dir" />
<cfset var sortDirList = "ASC,DESC" />
<cfset var columnList =
"NAME,SIZE,TYPE,DATELASTMODIFIED,ATTRIBUTES,MODE,DIRECTORY" />
<cftry>
<cfset attrArgs.recurse = ARGUMENTS.recurse />
<!--- Verify the directory exists before continuing --->
<cfif DirectoryExists(ourDir)>
<cfset attrArgs.directory = ourDir />
<cfelse>
<cfthrow type="Custom" errorcode="Our_Custom_Error"
message="The directory you are trying to reach does not exist." />
</cfif>
<!--- Conditionally apply some optional filtering and
sorting --->
<cfif IsDefined("ARGUMENTS.fileFilter")>
<cfset attrArgs.filter = ARGUMENTS.fileFilter />
</cfif>
<cfif IsDefined("ARGUMENTS.sortField")>
<cfif ListFindNoCase(columnList,ARGUMENTS.sortField)>
<cfset attrArgs.sort = ARGUMENTS.sortField & " " &
ARGUMENTS.sortDirection />
<cfelse>
<cfthrow type="custom" errorcode="Our_Custom_Error"
message="You have chosen an invalid sort field. Please use one of the
following: #columnList#" />
</cfif>
</cfif>
<cfdirectory action="list" name="q"
attributeCollection="#attrArgs#" />
<!--- If there are files and/or folders, and you want to
sort by TYPE --->
<cfif q.recordcount and IsDefined("ARGUMENTS.dirFilter")>
<cfif ListFindNoCase(filterList,ARGUMENTS.dirFilter)>
<cfquery name="retQ" dbtype="query">
SELECT #columnList#
FROM q
WHERE TYPE = '#ARGUMENTS.dirFilter#'
</cfquery>
<cfelse>
<cfthrow type="Custom" errorcode="Our_Custom_Error"
message="You have passed an invalid dirFilter. The only accepted values
ar File and Dir." />
</cfif>
<cfelse>
<cfset retQ = q />
</cfif>
<cfcatch type="any">
<!--- Place Error Handler Here --->
</cfcatch>
</cftry>
<cfreturn retQ />
</cffunction>
</cfcomponent>
--
Steve "Cutter" Blades
Adobe Certified Professional
Advanced Macromedia ColdFusion MX 7 Developer
_____________________________
http://blog.cutterscrossing.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315020
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4