0

I am trying to create global functions in Lucee. I have followed the directions here and have it "Kind of" working. Inside of Application.cfc I placed the following code:

public void function onRequest() {
    URL.IsInternalUser = function() { return (SESSION.user.ID ?: 0); };
}

This seems to work fine in some cases but if we need to access this function in a subdirectory that contains an Application.cfc that does not have the function re-defined it will error out saying the function doesn't exist.

The ultimate goal I am trying to achive is to have a cfc file that contains several user defined functions and then have them accessible throughout the entire application without redefining things over and over again.

Is there a better way to accomplish what we want? I ask this because on the page I referenced earlier in the comments section there is a quote:

I concur. Wouldn't surprise me to see it somewhere else in the future.

What I like about Railo's method is that it is completely sandboxed. Host A's tags & functions libraries never cross/conflict with Host B's libraries unless they're put into the global server folders. It's the same way for the virtual file system too and pretty much everything else (datasources, etc).

It specifically mentions Railo having a way to create UDF but I can not find any documentaion on this anywhere. Since we are using Lucee which is a fork of Railo I figure it must have what Railo has for creating UDF. Hoping someone that reads this can help me out and point me in the right direction.

Yamaha32088
  • 4,125
  • 9
  • 46
  • 97

1 Answers1

3

Railo/Lucee support custom functions. You can declare them in /WEB-INF/{railo|lucee}/library/function/ of the site. Save the function in a .cfm file and name the file the same as the function. The server needs a restart after creating new functions. Here is Railo's blog post about it.

Adobe ColdFusion doesn't support this AFAIK. So you have to store your functions in the SERVER scope here.

Alex
  • 7,743
  • 1
  • 18
  • 38
  • Wouldn't the WEB-INF directory get overwritten every time the server gets restarted? – Yamaha32088 Jun 15 '16 at 15:02
  • No, the WEB-INF is only created once with the start of the Railo/Lucee service. The directory then is kept and stores settings. – Alex Jun 15 '16 at 15:05
  • You don't have to store anything in the server scope for Adobe Cold Fusion. You just have to put the cfc in the default location for custom tags. – Dan Bracuk Jun 15 '16 at 15:11
  • @DanBracuk Just tested this in CF10 and it's not recognized, neither functions in a cfcomponent/cfc nor in a cfm. – Alex Jun 15 '16 at 15:25