- see footer for list info -<
On 25/05/06, RichL <[EMAIL PROTECTED]> wrote:
>- see footer for list info -<
Yes I know it is delay evaluation but I am still not 100% clear how the
combination of Evaluate() and DE() is helping achieve this... i.e. what
exactly CF is doing with this expression

Ah sorry... misunderstood what you were asking...

evaluate() wants to take filename.cfm and use it as a variable rather
than as part of a string,  so the de() delays the evaluation of path
until ##request.path## has been substituted with the contents of the
variable request.root.  The evaluate then runs on that string rather
than trying to eval the whole thing.

If you expand Adam's code to :

<cfset path ="##request.root##filename1.cfm">
<cfset request.root = "C:\Inetpub\wwwroot\">
<cfoutput>Full output: #evaluate(de(path))#<br />
Delayed bit: #de(path)#<br />
Eval request.root: #evaluate("##request.root##")#<br />
Eval just the path: #evaluate(path)#<br />
</cfoutput>

this should show you what's happening easier than my dodgy description.

I can't hardcode the full path in the database because we have different
paths for dev/test/live - which is where the request.root variable comes in
to play... but not only that we have different root variables

e.g.
request.appsroot
request.comproot
request.root

Ahh... yeah that was the only thing that came to mind when I was
replying this morning.

It might be cleaner and more efficient, if you are stuck with this
way, to use place holders rather than the coldfusion variable eg.
[root] instead of ##request.root##, [comproot] instead of
##request.comproot## and so on.

When you output the file path you would just replace the place holder
with the appropriate variable. eg.
replace(path,"[root]",request.root,"all")
You can probably do some clever bit of regex to get the placeholder
out of the variable path and use that to tell the replace() function
which placeholder to replace and which variable to use, but regex is
not my strong point, so I'll leave that to someone else :D (I forsee
use of back references)


I don't think I can use it directly in code because I don't know which one I
need hence the idea of putting the appropriate one in the configuration
table (each record in the table relates to an area of the site)

How do you decide which variable to use when you store the file path
in the data?

However you do it there's got to be better ways of managing this than
storing the variable in the db table and doing a evaluate(de(...)),
which is just really horrible...

Other than the fact this is something people trot out every now and
then... *why*?

Why is this horrible?  Because you're using evaluate() and you're
storing coldfusion code in the database, both of which aren't really
very good practice. Piled on top of that you have to use de() to get
the string out of the content to be processed by evaluate(), so you've
kind of got triple processing on this one little bit of code.

There is a discussion on the cfcdev list at the minute about the use
of evaluate to create dynamic calls to methods in cfcs.  The
conclusion I read this morning is that you shouldn't be using
evaluate, because it is very inefficient.  However, as long as you've
already instantiated your object using createobject() then using
evaluate might be more efficient than using <cfinvoke> repeatedly.  So
far this is about the only reason i can see where you should be using
evaluate() in coldfusion code. There are any number of ways to avoid
using evaluate in most everyday situtations.

Regards

Stephen
_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
- Hosting provided by www.cfmxhosting.co.uk -<
- Forum provided by www.fusetalk.com -<
- DHTML Menus provided by www.APYCOM.com -<
- Lists hosted by www.Gradwell.com -<
- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<

Reply via email to