Overriding a Wheels View Helper
Overriding a built-in ColdFusion on Wheels function is something I often see done by Wheels developers. It's a very useful technique for customizing a Wheels function while still keeping your code base clean.
Since there are some gotchas with the approach though, I'll show you a quick example of how it can be implemented.
Let's say we want to add the ability to strip Bulletin Board Code to the stripTags function. Your first instinct might be to code your own stripTags function and place it in the views/helpers.cfm file where view helper functions are typically placed.
Unfortunately you'll get a "Routines cannot be declared more than once" error if you do that though (or a similar error depending on the CFML server you have). This happens because the controller in Wheels includes all view functions and simply won't accept two functions with the same name.
The solution is to make use of the inheritance in Wheels and place the function in the controllers/Controller.cfc file instead. This component inherits all functions from a base Wheels controller component and thefore we can achieve something like what we have in the code below.
Here I have added my new BBCode argument and the custom code to handle the new functionality. Note how I call the parent stripTags functions using the "super" keyword and also clean up the arguments struct before passing it along.
With this in place all existing calls to stripTags in your code will behave exactly the same but you get the additional option of simply adding BBCode=true to the function calls to strip out Bulletin Board Code.
This same technique can of course be applied to controllers and models too.
You can also take it a step further by wrapping it up in a plugin but that's a post for another day...