Pablo Varando's ColdFusion Blog

Tracking user clicks.... one way....

A few days ago a user on Easy asked a question about tracking users click through your site, like a breadcrumbs.... now naturally my suggestion was to insert a value to the database and then (based on the user's IP address) return back the data for display. This is still my favorite solution as it is quick and painless; the user however asked me to provide a solution that did not involve the database... so here goes nothing.... (disclaimer, use the database it's better and allows you to get data long term, but for a short timespan type thing this might help you... so I thought I'd post it.


Put this in your application.cfm or application.cfc
(onRequestStart).

<!--- create an application structure to track all
users --->

<cfparam name="application.clickStream"
default="#structNew()#" />

<!--- create an array in the structure for this user
(by ip) --->

<cfparam
name="application.clickStream['user_'&cgi.REMOTE_ADDR]"
default="#arrayNew(1)#" />


<!--- now insert this current page for this user --->
<cfset application.clickStream['user_'&cgi.REMOTE_ADDR][val(ar
rayLen(application.clickStream['user_'&cgi.REMOTE_ADDR]
)+1)] = cgi.SCRIPT_NAME /
>



<!--- THIS you can use to see the actual dump of all
users... --->


<cfdump var="#application.clickStream#" />

As mentioned before, the database is the best route; but this is one route you could go.

What is a good ColdFusion Book these days?

You know, I read books on ColdFusion all the time (I fly a lot) to stay up to par with things, but mostly to get different perspectives on how people see and use ColdFusion in their own lives. We all have our own perspective and uses; and I like to see how others use it and/or teach it.. (the teach it part intrigues me, because I teach it too.. so i do my best to learn from others and see what works and what doesn't so I can do it better myself).

Recently, I got my hands on a copy of John Farrar's [ColdFusion 8 Developer Tutorial] and I have to say.. I think it's clearly written...it covers a broad range of subjects, but I think what I like the most is that it goes above and beyond most books. He clearly focuses on the readers and does everything possible to get you to get it... (if that makes sense).

I am not one to recommend books, I think tutorials and "demonstrations" work better when it comes to learning things, but I think that this book can teach people quite a bit and really get them to understand and master the coding logic that is needed to become a good developer.

If you have yet to read this book, I suggest you pick up a copy.. It's not only worth the cash.. but will also be a good reference later on.. Lots of Ajax in there too.. which I haven't seen in many other books (other than WACK... but that is another story!).

Overall, I would give this book a 4.5 (out of 5 stars) because it delivers a good range of topics, clear communication, and most importantly it helps with next steps!

Great Job John!
Keep them coming!


Want to get your own copy of the recommended book?

CFML (for mobile phones?)

I wanted to see if anyone out there is interested in helping me build a new CFML framework.

Why build a new framework when you have 50 of them out there now?
I want to make a Mobile Phone framework powered by CFML, Stylesheets and more.

I would like to build a CFML tag framework that would enable developers to build mobile compliant website, easily and quickly. If you have experience building mobile compliant web sites, please let me know (even if you can't help.. I might be interested in asking some questions or getting some feedback from you to get this framework going!)

I have registered a domain name "cfml.mobi" which I am finihsing up a site for; however if after we got this going we want to change the name as a team; I am willing to do that too, just trying to be pro-active! :)

I wanted to see if there was anyone out there interested in being part of the development of the framework. Let me know your thoughts and if you're interested in being part of the team... Drop me an email in this post!

Thanks,
Pablo Varando

ColdFusion Careers - Site is live... Post jobs, Find Jobs and more!

I wanted to announce a quick blur about a new site I just made live and will be pushing... It's titled "ColdFusion Careers"... It's basically a job board around ColdFusion jobs... Previously I talked about what it means to be a ColdFusion developers these days; and with the toughness recruiters and hr firms are having finding ColdFusion developers; I wanted to launch something that is simple and free to use.

You can check out: http://www.coldfusioncareers.com

If you're looking for a new career or just want to put your resume out there; plase add yourself..

I will also be releasing a full API webservice so you can add job searching, applying and more soon to your own sites... Also working on a referal system so if someone gets hired via your web site; you an earn that referral commissions... Sometimes those are like $500.00 per referral.. so it could be a good way for you to earn extra cash!

Anyways, check out the site and let me know what you think...

http://www.coldfusioncareers.com

P

What is the best way to show categories (and their children, and their children and those children)

Today I ran by a forum post on EasyCFM.COM (see it here) that asked for help in displaying categories. This can be tricky; especially if you have many parent/child relationships. So I thought I would post a blog entry talking about the best way I have found to do this... Here goes nothing..

First you need to create the database for it... so lets make a table and cll it "categories".

In that table you will need to have the following items:

categoryID int identity (autonumber).
category   nvarchar(50) (string/text)
parentcategoryID int (number)

Then in that database; we will put in a few records (Let's do (3) layers).

CategoryID    Category             ParentCategoryID
1             Automotive           0
2             Real Estate          0
3             Used                 1
4             New                  1
5             For Sale             2
6             For Rent             2
7             Homes                5
8             Apartments           5
9             Homes                6
10            Apartments           6

Now notice that you have two records that are "master" records... Or top level which have a parentID of "0". This means that these are the ones that will show up in bold and are special :)

Now inside of that we created a (3) level one as follows, the other one has only two levels:

Real Estate
   > For Sale
       > Homes
       > Apartments
   For Rent
       > Homes
       > Apartments

Now to show them on a page all the way down, can be tricky if you code it; since it will require you to loop through the ones with a "0" and then do another query and loop through it and then do it again and again... so how do you accommodate for as many levels as you may need.. (imagine one has 40 levels deep)....

This is wehre custom tags really do come in handy... You can do a custom tag that will call itself over and over and over until it doesnt need to anymore... So how do you ask?

Well, let's show you...

First lets create a custom tag and let's call the file "categories.cfm"; on this page lets put this code:

<!--- this is a custom tag that will loop over itself and show categories and their children --->

<!--- first let's allow you to pass in a variable that will tell the system which categories to show --->
<cfparam name="attributes.ParentCategoryID" default="0" />

<!--- now let's hit the database and call the records --->
<cfquery name="qGetCategories" datasource="#request.dsn#">
select categoryID, category
from categories
where ParentCategoryID = #val(attributes.ParentCategoryID)#
</cfquery>

<!--- now let's show the categories --->
<cfoutput query="qGetCategories">
<a href="apage.cfm?categoryID=#val(categoryID)#">#category#</a><br />
<!--- now here goes teh magic... here let's have it call itself (the same page) but with a different ParentCategoryID ID value so it gets this records children --->
<cf_categories ParentCategoryID="#categoryID#">
</cfoutput>

That's pretty much it... now on the main page (where you want the parent categories to always show up) let's call the custom tag with a ParentCategoryID of "0" (again, remember this is the master records).

<cf_categories ParentCategoryID="0">

How easy was that? Now this baby can go 1, 2, 10, 40, 60, 100 levels deep and you don't have to do anyhing else... Sweeet..

If you want to only force it to go "2" levels down... you can do this:

<!--- now let's show the categories --->
<cfoutput query="qGetCategories">
<a href="apage.cfm?categoryID=#val(categoryID)#">#category#</a><br />
<!--- now here goes teh magic... here let's have it call itself (the same page) but with a different ParentCategoryID ID value so it gets this records children --->
<cfif attributes.ParentCategoryID EQ 0>
<cf_categories ParentCategoryID="#categoryID#">
</cfif>
</cfoutput>

That will only run one time when you call the parent caegories... then the parent's grandchildren will not be show; because when you call that tag again for the third time.. the ParentCategoryID will be higher then zero... make sense?

Let me know your thoughts....

-P

ColdFusion 5 - Get Image Information....

There are a couple of ways to achieve this... I've found out once again.... It's been a while since I used CF 5... WOW what a difference 8 is to it... anyways, back to the topic.

The first way

<cfset imgFile = createObject("java","javax.swing.ImageIcon").init(expandPath('/images/fileName.jpg'))>
<cfset imgFile.getImage()>
<cfset imgWidth = imgFile.getIconWidth()>
<cfset imgHeight = imgFile.getIconHeight()>

For this however, Java must be installed on the server. I know it's installed by default with ColdFusion MX or higher... but not the case all the time with CF 5.

There are a few tags (This is the one I recommend) that will also do the trick; however some are cheap, some are free and the one I used costs around $100 bucks.

The tag is Efflare ImageCR (you can get it here: http://www.efflare.com )

You can read the documentation, but since the library is written in c++ it is compatible with CF 5... so there goes that... let me know if you have any questions!

Image Processing under ColdFusion 5.... A little blast from the past...

Today I ran by a post on the EasyCFM.COM forums; where the individual is still using ColdFusion 5 and is trying to get the image width/height values of a given image.

I know that CF 5 is a bit outdated; but I'm feeling a bit nostalgic and so I am gonna install CF 5 on a local box and see if I can get something going for him... I wanted to post a little something mentioning this as I will be posting a follow up shortly with a solution... wish me luck :) hehe

Back in a bit... :-)