Sorting methods in your components

Working on a project where I need to compare the functions in one components to insure that they were present in another and the logical way to accomplish this was to get my methods sorted into alphabetical order.

It's not much code and pretty self explanatory as to what its doing so I am not going to explain it line by line. Feel free to ask questions if you have any.

view plain print about
1<cfsilent>
2<cffile action="read" file="physical/path/to/your/component" variable="cfc">
3<cfscript>
4    function getMethods() {
5        regex = '<cffunction((\s+\w+(\s*=\s*?:".*?"|.*?|[^">
\s]+)?)+\s*|\s*)/?>
(.*?)</cffunction>';
6        start = 1;
7        length = len(cfc);
8        methods = structNew();
9        do {
10            method = {};    
11            matches = REFind(regex,cfc,start,"true");
12            if(matches.pos[1]+matches.len[1] NEQ 0) {
13                name = getName(mid(cfc, matches.pos[2], matches.len[2]));
14                method[name] = mid(cfc, matches.pos[1], matches.len[1]);
15                structAppend(methods,method);
16                start = matches.pos[1]+matches.len[1];
17            } else {
18             start = length;    
19            }
20        }
21        while (start NEQ length);
22    return methods;
23    }
24    function getName(s) {
25        var i = 1;
26        for(i=1;i<=listLen(s," "); i++) {
27            if(find("name",listGetAt(s,i," "))) {
28                name = listGetAt(s,i," ");
29            }
30        }
31        name = replace(name,"name=""","");
32        name = replace(name,"""","");
33        return name;
34    }
35</cfscript>
36<cfset methods = getMethods(cfc)>
37<cfset sorted = structSort(methods,'textnocase','asc')>
38</cfsilent>
39<cfoutput>
40<cfloop array="#sorted#" index="function">
41#methods[function]#
42</cfloop>
43</cfoutput>

run the code above and view the source to view the results. May look at making this a Coldfusion Builder Extension at some point.

Endless scrolling with jQuery and Coldfusion using ORM

Been on Facebook, Twitter or any number of sites that loads data as you scroll? I would bet that most of you have. lets show you how to set up your site to load data inline while the user scrolls down the page.

The first steps is to get the initial set of data and a record count for the entire dataset that is going to be loaded up. This is pretty much standard Coldfusion nothing fancy.

view plain print about
1<cfset numRecords = ormExecuteQuery("select count(*) as total from entries")>
2 <invalidTag>
3    //Will discuss the script section below.
4 </script>
5 <cfoutput>
6    <cfset entries = entityload("entries",{},{maxResults=10,offset=0})>
7        <div id="entries">
8            <cfloop array="#entries#" index="e">
9            <div class="entry">
10                <h3 class="title"><a href="#e.getUrl()#">#e.getTitle()#</a></h3>
11                <div class="content">#e.getContent()#</div>
12            </div>
13            </cfloop>
14        </div>
15 </cfoutput>

[More]

Using parameters with ormExecuteQuery and Railo

Though the new ORM functions in Railo are great there is often times you need just a little more than matching one or two columns exactly when you're getting data. When you reach this point it's time to bring in ormExecuteQuery as a method of gaining that little bit more of control over getting your data. Though there is more to ormExecuteQuery but I want to discuss how to use the conditional parameters of your where clause.

Though you could just insert the parameters directly into your query, we all know that that is not safe and is how SQL Injection attacks occur. In fact I am not even going to show that as we don't even want you to think about doing it that way, and since cfqueryparam cannot be used here we need to find another way to keep our system secure but get the data we need.

[More]