|
As you might know of me, I am actually loving CFWheels (wife at first priority ofcourse!), ever since I discovered it. Discovered it through a friend/collegue that pointed out to me that there was a much more simplified MVC framework than the model-glue and mach-ii that we were working with at the company at that time.
So as soon as I put some time into checking it out, reading all the tutorials, watching the videos, watched some presentations both live and offline at cfmeetup and also tryed out some scripting with it myself, I was sold! This is THE framework for me. So from now on I develop in CFWheels. From now on.. meaning that all old projects and websites are mostly still in the old crap code written. I sure plan to write some of them into CFWheels as well soon, but they aren't very high on my prioritylist. So if you wonder, this weblog system is still written in 'Steven framework code'.
There are several projects going on at this moment, but I wasn't quite sure which one would launch first of them all. Well than I took the smallest yesterday to complete first, which also helps me to promote the others afterwards, so that's a nice addition to it all.
So you can expect a lot coming from me still the coming months.
Anyway, back to the actual subject, I've made an application which already exists over 100 times in the world of internet, but I just thought it was fun to create something simple as that with CFWheels to show the power of it. Anyone familiar with TinyURL? Yes, that is a system that creates short url's from long url's.
Well, ac2.nl Shortlink service is now also available for you! It was one of my smallest domains that I still had in my domainregistrar account, so I thought, why not..
I have made use of the routing system of CFWheels to create the shortlink codes on the url.
Shortlinks start with ac2.nl/l/{code}
So: <cfset addRoute(name="ShortLink", pattern="/l/[shortcode]", controller="shorturl", action="geturl")>
I had to do this in a virtual subfolder, because else I couldn't display any main pages anymore for the actual creation of shortlinks.
Also I use the same type of tinyURL javascripted button you can move to your favourites bar, so I also created a route for the button:
<cfset addRoute(name="URLButton", pattern="/Shorturl/buttoncreate_short/[url]", controller="Shorturl", action="createbutton_short")>
And then ofcourse a route for the home action:
<cfset addRoute(name="home", pattern="", controller="Shorturl", action="index")>
When you enter a URL in the form and request a shortlink at [www.ac2.nl], the system will generate a shortcode for you and present you the new link. As the user can give also a custom shortlink name, I had to add the option to save the custom name as the shortlink code. As this code has to be unique, I first used the model to make it unique:
<cfset validatesPresenceOf("url,shortcode")> <cfset validatesLengthOf(property="shortcode", minimum="3", maximum="50", message="Give a value between 3 and 50")> <cfset validatesUniquenessOf("shortcode")>
This though created the problem that if you don't give a custom shortcode, it wouldn't have the length required (empty shortcode means 0) and without the length validation, the uniqueness validation would throw an error after creating one empty entry (double empty entry isn't unique either).
So I stepped away from that again and created just simply a check with a query inside the cfif on a value in the custom shortcode field.
As for the code generation, this is currently a very simple version. I create the record for the URL, then pick straight away the ID on creation (it's returned in the struct with which you create a record) and do a simple obfuscateParam() over it to create a shortcode and save it away on the same record.
Ofcourse, this isn't the best code you can create, but it suits for the example I think. So basicly our shortcode is a encoded recordID in the url table.
As for the button, it's similar code for the creation of a shortcode apart from the custom shortcode. Upon clicking the button, a shortcode is generated immediatly and presented to the user.
Next on was creation of a simple API. This I did via a webservice that can simply create new shortlinks and retrieve long url's from shortlink codes. The webservice takes two methods: - createlink() - retrievelink()
The webservice files had to be placed in the miscellaneous folder as to exclude them from the frameworks request system.
Thinking of it now, I could just have requested creation of links on base of my own created webservice, but nahh.. that wouldn't demonstrate much of the frameworks MVC that way, plus it would overload the requests on the API I think (in a full production environment).
Well as you figured, this was just a small project on my side, so expect pretty soon much more released and announced via my weblog.
Feel free to comment / ask questions about the framework or my experience on making this application. |