Understanding Helpers and User Defined Functions

273 views
Skip to first unread message

Nathan Stanford Sr

unread,
Aug 19, 2011, 4:30:05 PM8/19/11
to col...@googlegroups.com
I know there is the  /includes/helpers/ApplicationHelper.cfm

I think I saw where you could put helpers in view file like

/views/test/myveiw.cfm
/views/test/myveiwHelper.cfm put the UDF's in here just for this view only.

Is this true?

If not then what is the best Practice for this?

Nathan Stanford Sr

unread,
Aug 19, 2011, 4:40:14 PM8/19/11
to col...@googlegroups.com
Is there a way to include a helper that is not global in side of one or two handlers?

or in the Model?


br...@bradwood.com

unread,
Aug 19, 2011, 4:43:38 PM8/19/11
to col...@googlegroups.com
It is true. 

What you describe is called impicit view helpers.

You can also get more reusable and manually include helper UDFs wherever you need them.

Thanks!

~Brad


--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To post to this group, send email to col...@googlegroups.com
To unsubscribe from this group, send email to coldbox-u...@googlegroups.com
For more options, visit this group at http://groups-beta.google.com/group/coldbox
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org

br...@bradwood.com

unread,
Aug 19, 2011, 5:01:29 PM8/19/11
to col...@googlegroups.com


As far as my models, my application has a supertype component that everything inherits from where I put some basic stuff like cfscript versions of dump and mail.  (I'm still on CF8 as work)

As far as utility functions like formatting and conversion, I keep those in a CFC and either inject a reference to that CFC, or to that method. 

I have this dummy CFC that returns references to my UDFs:

<cfcomponent name="UDF" hint="I am a UDF loader." output="no" autowire="true">
    <cfproperty name="UDFLibraryFile" inject="coldbox:setting:UDFLibraryFile" scope="variables">

    <cffunction name="init" output="false">
        <cfinclude template="#UDFLibraryFile#">
        <cfreturn this>
    </cffunction>
   
    <cffunction name="onMissingMethod" access="public" output="false"
        hint="Instead of implementing each UDF here, I load the UDF from it's location based on the missing method name.">
        <cfargument name="MissingMethodName"/>
        <cfargument name="MissingMethodArgumnts" hint="not supported by coldbox DI DSL"/>
        <cfreturn variables[MissingMethodName]>
    </cffunction>
   
</cfcomponent>

When I want a reference to a single method out of my UDF library, I ask wirebox to inject "model:UDF:myUDFName".  That hits the dummy CFC above and returns a reference to that method which gets mixed directly in to my model. 

You might not like that, but I thought I would share what we had cooked up at my job.  I've actually wanted to talk to Luis about an enhancement to WireBox DLS to allow you to request a single method be mixed in in a similar fashion without the need for the dummy CFC above.

Thanks!

~Brad

-------- Original Message --------
Subject: [coldbox:11249] Re: Understanding Helpers and User Defined
Functions
From: Nathan Stanford Sr <nathan....@gmail.com>
Reply all
Reply to author
Forward
0 new messages