|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Won't evaluate?
Author: James Holmes
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313774
And finally, do you really want a user to be able to add any random CF
expression into the DB to be executed? Combine this with something like a
URL variable or form post and the results could make SQL injection look like
a minor inconvenience.
Replacing placeholders is much safer.
mxAjax / CFAjax docs and other useful articles:
http://www.bifrost.com.au/blog/
2008/10/11 Aaron Rouse <aaron.rouse@gmail.com>
> Yeah but you have to be careful with how much you use those functions in an
> application. I know at least on our CF6 server here for one project that
> extensively uses those it does in fact eat up a good bit of resources when
> a
> normal user load is on it.
Author: Aaron Rouse
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313773
Yeah but you have to be careful with how much you use those functions in an
application. I know at least on our CF6 server here for one project that
extensively uses those it does in fact eat up a good bit of resources when a
normal user load is on it.
----- Excess quoted text cut - see Original Post for more -----
Author: Ian Skinner
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313771
Ian Skinner wrote:
----- Excess quoted text cut - see Original Post for more -----
O.K.!!!! I have never really done anything with this recursive rendering
of ColdFusion variables inside of ColdFusion variables before. But this
is kind of cool to my geeky soul!!! In a very much, 'Why the hell would
you ever do this!' way
<cfset aString = "Here is some ##change_this## text.">
<cfset change_this = "(The quick brown fox jumped ##myOhMy## over the
lazy dog.)">
<cfset myOhMy = "{{You have got ##no_do_not_do_it## to be kidding!}}">
<cfset no_do_not_do_it = "[[[Stop this madness now!!!!]]]">
<cfoutput>
#aString#
<hr />
#evaluate(de(aString))#
<hr />
#evaluate(de(evaluate(de(aString))))#
<hr />
#evaluate(de(evaluate(de(evaluate(de(aString))))))#
<hr />
</cfoutput>
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313770
Thanks! :) This makes it allot easier. :)
Ian Skinner wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Ian Skinner
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313769
----- Excess quoted text cut - see Original Post for more -----
Going back to you original question, contrary to Azadi's and Matt's answers, you
can do this. I am not sure this is better then the replacement technique that
has already been worked out, but in the names of fairness and completeness. You
could have done something like this.
<cfoutput query="FAQ">
<div class="FAQAnswer">
#Evaluate(DE(FAQ.Answer))#
</div>
</cfoutput>
It requires a combination of the de() 'delay evaluate' and evaluate() functions
to get ColdFusion to render variables contained inside of string variables. No
guarantees on how robust this solution is, but it is technically possible.
Author: Claude Schneegans
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313767
>>Yes, I know scoping my variables is a
good thing now and I will from now on when needed. But honestly, it so
rarely comes up as an issue
Right. A good practice to avoid trouble if you don't scope is at least
to use different
names for variables in different scopes, especially with queries.
The problem with queries is that inside a <CFOUTPUT on a query, the
query scope
become implicit and have precedence over the variables scope, but not
outside.
Using different names will prevent confusions.
Like in your case <cfset FAQQuestion = Replace(FAQ.Question
instead of <cfset Question = Replace(FAQ.Question
Author: Aaron Rouse
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313764
I became a scoping nazi back when I had to start working with a home built
framework that did not scope a single thing. It made it rather difficult to
back track through things and see how it was supposed to be working(since it
did not always work right).
On Fri, Oct 10, 2008 at 3:13 PM, Eric Roberts <
owner@threeravensconsulting.com> wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Eric Roberts
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313763
I used to not scope and had to teach myself to scope and break that
habit...next one I am working on is cfqueryparam...
One day at a time...
Maybe we need to create a 12 step program for CF developers hehehe *grin*
Eric
/*-----Original Message-----
/*
/*Sent: Friday, October 10, 2008 2:28 PM
/*To: cf-talk
/*Subject: Re: Won't evaluate?
/*
/*While the naming is bad, why not learn from the experience and try to
/*scope
/*things? It could save you a lot of random headaches over the years.
/*
/*On Fri, Oct 10, 2008 at 2:22 PM, Phillip M. Vector <
/*Vector@mostdeadlygame.com> wrote:
/*
/*> Ian Skinner wrote:
/*> > <div class="FAQQuestion">
/*> > #Question#
/*> > </div>
/*> >
/*> > Is ColdFusion seeing that as 'variables.question' or
/*> 'variables.FAQ.question' you have both on this block of code. And it
/*may
/*> not be picking the one you want to output. If so then be specific in
/*which
/*> one you want.
/*>
/*> OOOohhh.... *slaps forehead* I get the idea now.. Thanks. I can name
/*> them Q and A and use that (Yup. Tried it and it works). Yeah... I feel
/*> stupid now. :)
/*>
/*>
/*
/*
Author: Eric Roberts
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313762
We all have our slow days Philip :-D It's a good thing slapping of the
forehead doesn't leave permanent marks...I would be so disfigured if that
were the case hehehe.
Eric
/*-----Original Message-----
/*
/*Sent: Friday, October 10, 2008 2:23 PM
/*To: cf-talk
/*Subject: Re: Won't evaluate?
/*
/*Ian Skinner wrote:
/*> <div class="FAQQuestion">
/*> #Question#
/*> </div>
/*>
/*> Is ColdFusion seeing that as 'variables.question' or
/*'variables.FAQ.question' you have both on this block of code. And it may
/*not be picking the one you want to output. If so then be specific in
/*which one you want.
/*
/*OOOohhh.... *slaps forehead* I get the idea now.. Thanks. I can name
/*them Q and A and use that (Yup. Tried it and it works). Yeah... I feel
/*stupid now. :)
/*
/*
Author: Dave Francis
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313761
Just wondering out loud... Is it possibly treating $$ as $, like for
quotes and hashes? Also, try it without any variables ie. Replace("ABC
$$UserCount XYZ", '$$UserCount$$', "999", "ALL"), then introduce them 1
at a time until it breaks.
Claude Schneegans wrote:
> >>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")
>
> It may also be an question of upper/lower case.
> Are you sure you always have "UserCount" ?
> If not, use replaceNoCase() instead.
It's exactly that.
> >>just doesn't show any usercount.
>
> Does it show any '$$UserCount$$' then ?
Yes. Here is what it shows..
===========================
What is LARP?
$$UserCount$$
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313760
Ian Skinner wrote:
> Or just be specific in what you wanted to output. Modifying your
> original code in the following manner will achieve the exact same result
> as changing the variable names, and demonstrates a better practice of
> scoping your variables. I hope you at least wrote that as 'variables.q'
> and 'variables.a'! :-)
Fair enough. No, I didn't actually name them Q and A. :) I named them
"AdjustedQuestion" and "AdjustedAnswer".
As for putting variable. before every variable will take quite a bit of
work for the app I'm working on. Yes, I know scoping my variables is a
good thing now and I will from now on when needed. But honestly, it so
rarely comes up as an issue (I don't know what I was doing naming the
variable the same name as the field) that it seems redundant to do so
(well, until something like this happens). :)
Author: Ian Skinner
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313759
Phillip M. Vector wrote:
----- Excess quoted text cut - see Original Post for more -----
Or just be specific in what you wanted to output. Modifying your
original code in the following manner will achieve the exact same result
as changing the variable names, and demonstrates a better practice of
scoping your variables. I hope you at least wrote that as 'variables.q'
and 'variables.a'! :-)
<div class="FAQQuestion">
#variables.Question#
</div>
Author: Aaron Rouse
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313758
While the naming is bad, why not learn from the experience and try to scope
things? It could save you a lot of random headaches over the years.
On Fri, Oct 10, 2008 at 2:22 PM, Phillip M. Vector <
Vector@mostdeadlygame.com> wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313757
Thanks for the explination. I understand the issue now. :)
Peter Boughton wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313756
Ian Skinner wrote:
> <div class="FAQQuestion">
> #Question#
> </div>
>
> Is ColdFusion seeing that as 'variables.question' or
'variables.FAQ.question' you have both on this block of code. And it may not be
picking the one you want to output. If so then be specific in which one you
want.
OOOohhh.... *slaps forehead* I get the idea now.. Thanks. I can name
them Q and A and use that (Yup. Tried it and it works). Yeah... I feel
stupid now.
:)
Author: Aaron Rouse
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313755
Like I said if it is in a loop over a query then you need to scope the
variables within the div elements.
That is your problem.
On Fri, Oct 10, 2008 at 1:57 PM, Phillip M. Vector <
Vector@mostdeadlygame.com> wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Ian Skinner
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313754
Phillip M. Vector wrote:
> Peter Boughton wrote:
>
>> 1) Scope the variable, e.g. using #Variables.Question# instead of just
#Question#
Did you do this one Phillip.
I'm late to this discussion so I don't really know what your issue is.
But you have some pretty ambiguous code here.
<div class="FAQQuestion">
#Question#
</div>
Is ColdFusion seeing that as 'variables.question' or 'variables.FAQ.question' you
have both on this block of code. And it may not be picking the one you want to
output. If so then be specific in which one you want.
Author: Peter Boughton
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313753
>I'm just using a cfoutput querry loop.
>
>But I put in [CurrentRow] just in case. No change. Still not working.
Not sure if you're understanding fully, so I'll simplify completely:
(apologies if any of this is patronising)
This code here:
<cfoutput query="FAQ">
#Question#
</cfoutput>
Will do the same as this:
<cfoutput query="FAQ">
#FAQ.Question[FAQ.CurrentRow]#
</cfoutput>
If you did this:
<cfoutput query="FAQ">
<cfset Variables.Question = "X"/>
#FAQ.Question[FAQ.CurrentRow]#
</cfoutput>
You wouldn't be surprised that the output didn't change (I hope).
The following is IDENTICAL to ColdFusion as the above code:
<cfoutput query="FAQ">
<cfset Variables.Question = "X"/>
#Question#
</cfoutput>
And this code is also IDENTICAL to ColdFusion as both the above:
<cfoutput query="FAQ">
<cfset Question = "X"/>
#Question#
</cfoutput>
In other words, when you *set* the variable Question, it goes into the global
Variables scope.
However, when you *read* the variable Question, because you are looping through
the query, it looks first in the query's scope.
This is one of the reasons you find many people saying you should always scope
all variables - it avoids issues like this.
To make things work as you want, you need to either read the global Variables
scope, or instead to change the value within the query scope.
All make sense?
Author: rex
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313751
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Like Aaron and Peter said, SCOPE your variables like so:
<cfoutput query="FAQ">
<cfset VARIABLES.UserCount = Users.Recordcount>
<cfset VARIABLES.Question = Replace(FAQ.Question, '$$UserCount$$',
VARIABLES.usercount, "ALL")>
<cfset VARIABLES.Answer = Replace(FAQ.Question, '$$UserCount$$',
VARIABLES.usercount, "ALL")>
<a name="#FAQ.FAQID#"></a>
<div class="FAQQuestion">
#VARIABLES.Question#
</div>
<P>
<div class="FAQAnswer">
#VARIABLES.Answer#
</div>
<HR>
</cfoutput>
When you are referencing #Question# you are actually referencing
#FAQ.Question# and not #VARIABLES.Question#, so it wont work
Phillip M. Vector wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313752
Claude Schneegans wrote:
> >>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")
>
> It may also be an question of upper/lower case.
> Are you sure you always have "UserCount" ?
> If not, use replaceNoCase() instead.
It's exactly that.
> >>just doesn't show any usercount.
>
> Does it show any '$$UserCount$$' then ?
Yes. Here is what it shows..
===========================
What is LARP?
$$UserCount$$
Author: Claude Schneegans
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313748
>>Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")
It may also be an question of upper/lower case.
Are you sure you always have "UserCount" ?
If not, use replaceNoCase() instead.
>>just doesn't show any usercount.
Does it show any '$$UserCount$$' then ?
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313747
Heh.. True enough.
Peter Boughton wrote:
> If you have someone kick you every time you do it, you can break most habits
much quicker. :)
Author: Peter Boughton
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313745
> old habbits are hard to break.
If you have someone kick you every time you do it, you can break most habits much
quicker. :)
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313746
I'm just using a cfoutput querry loop.
But I put in [CurrentRow] just in case. No change. Still not working.
Peter Boughton wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313743
Here's the full code.
<cfoutput query="FAQ">
<cfset UserCount = Users.Recordcount>
<cfset Question = Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")>
<cfset Answer = Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")>
<a name="#FAQ.FAQID#"></a>
<div class="FAQQuestion">
#Question#
</div>
<P>
<div class="FAQAnswer">
#Answer#
</div>
<HR>
</cfoutput>
So yeah. it's looping fine. Just doesn't show any usercount.
Aar
> Is it inside a loop over a query? If so then scope your outputed variables
> in those div elements.
Author: Peter Boughton
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313744
>Is it inside a loop over a query? If so then scope your outputed variables
>in those div elements.
That sounds likely to be the problem - CF will give priority to the query vars in
resolving unscoped variables.
To clarify a little, the possible solutions are:
1) Scope the variable, e.g. using #Variables.Question# instead of just #Question#
2) Overwrite the values in the query, i.e. <cfset FAQ.Question[CurrentRow] =
replace(...) >
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313742
Peter Boughton wrote:
> Not sure - make sure the database contains this text:
> "We have currently $$UserCount$$ players signed up with this site"
Yup. That's all that is in the field.
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313741
I know.. I know.. It isn't pretty code.. But it's how I learned how to
do it and old habbits are hard to break. I seriously doubt that the #'s
are messing things up.
Yup. Cleaned it up and it's still not displaying correctly.
Claude Schneegans wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Claude Schneegans
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313740
>>So why isn't this working then?
>> <cfset UserCount = #Users.Recordcount#>
>> <cfset Question = #Replace(FAQ.Question, '$$UserCount$$',
#usercount#, "ALL")#>
You're not using # signs correctly :
<cfset UserCount = Users.Recordcount>
<cfset Question = Replace(FAQ.Question, '$$UserCount$$', usercount, "ALL")>
# sign should be used only inside <CFOUTPUT tags, rarely inside other CF
tags.
But this may not be the only
reason.
Author: Peter Boughton
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313739
>So why isn't this working then?
>
> [snip]
Not sure - make sure the database contains this text:
"We have currently $$UserCount$$ players signed up with this site"
?
Also, your code has far too many hashes - here it is cleaned up a little:
<cfset UserCount = Users.RecordCount>
<cfset Question = Replace( FAQ.Question , '$$UserCount$$' , UserCount , "ALL"
)>
<cfset Answer = Replace( FAQ.Answer , '$$UserCount$$' , UserCount , "ALL"
)>
<cfoutput>
<div class="FAQQuestion" id="#FAQ.FAQID#">
#Question#
</div>
<div class="FAQAnswer">
#Answer#
</div>
</cfoutput>
Author: Aaron Rouse
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313738
Is it inside a loop over a query? If so then scope your outputed variables
in those div elements. Also do not need the pound signs in your two cfsets
both on the replace functions and the usercount variables.
On Fri, Oct 10, 2008 at 1:40 PM, Phillip M. Vector <
Vector@mostdeadlygame.com> wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313737
So why isn't this working then?
<cfset UserCount = #Users.Recordcount#>
<cfset Question = #Replace(FAQ.Question, '$$UserCount$$', #usercount#,
"ALL")#>
<cfset Answer = #Replace(FAQ.Answer, '$$UserCount$$', #usercount#,
"ALL")#>
<a name="#FAQ.FAQID#"></a>
<div class="FAQQuestion">
#Question#
</div>
<P>
<div class="FAQAnswer">
#Answer#
</div>
Azadi Saryev wrote:
> another alternative may be to get your users.recordcount number in a
> variable in the page that displays the answer, and in your text in db
> store a placeholder, like $$usersnumber$$, and then at cfoutput replace
> the placeholder text with the actual number from the variable in the
page.
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313704
Ok.. Thanks. :)
Matt Quackenbush wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Matt Quackenbush
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313702
The short answer is: you don't.
The longer version is, you can setup placeholders and do a replace on them
to enter the values that you're wanting to use.
On Thu, Oct 9, 2008 at 8:38 PM, Phillip M. Vector wrote:
> How do I make CF treat data it pulls from the DB as variables and not a
> string?
>
Author: Azadi Saryev
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313700
cf won't evaluate your variable inside a variable (#users.recordcount#
inside #FAQ.answer").
you best bet will be to either store that text in a cfm file and
cfinclude it, or do it on the fly by pulling that text from db, writing
it to a temp file and cfinclude that file.
another alternative may be to get your users.recordcount number in a
variable in the page that displays the answer, and in your text in db
store a placeholder, like $$usersnumber$$, and then at cfoutput replace
the placeholder text with the actual number from the variable in the page.
hth
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Phillip M. Vector wrote:
----- Excess quoted text cut - see Original Post for more -----
Author: Phillip M. Vector
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57778#313699
I have in my DB under the field of answer...
We have currently #users.recordcount# players signed up with this site
that your event would reach. While it may not be many in the pure view,
if 7 come to your convention, that would pay for our services (Figuring
the room costs a total of $200 and you charge $30 for admission). Any
above that can't hurt your bottom line.
exactly. The #users.recordcount# as well.
When I run this code..
<cfoutput query="FAQ">
<div class="FAQAnswer">
#Evaluate("FAQ.Answer")#
</div>
</cfoutput>
It shows #users.recordcount# (with the pound signs) and not 32 like I
would think it would.. I tried also just putting #FAQ.Answer#, but that
doesn't work either.
How do I make CF treat data it pulls from the DB as variables and not a
string?
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||