EasyCFM.COM ColdFusion Forums / General Discussion / <rant type="minor" target="cfscript" />

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: <rant type="minor" target="cfscript" /> -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

Lossed
04-22-2007 @ 5:25 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

Whenever i get a really nice flow happening in cfscript, I have to break out of it to do a query or some other code not supported in cfscript. It can be very frustrating and I hate having to make the same checks for conditions outside the cfscript that were already handled inside it, before running the non-cfscript code. Either that or I have to set flags in cfscript to test for outside it b4 running the non-cfscript code.

Gawwwwd that's a PITA!


Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

GrowlyBear
04-22-2007 @ 6:44 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1314
Joined: May 2004

I don't know cfscript. I normally relay on the kindness of you guys to help me with that.
I have a phobia about scripts.

Can you do a cfscript..code code..cfc..code?
as in (forgive my totally crappy script)

if(blah == blah){
something;
somethingelse = cfcfunction();
}



~~~~~~~~~~~~~~~~~~~
CF Blogger
http://www.cfblogger.com

Lossed
04-22-2007 @ 7:09 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

yeap, sure can. Just gotta creat an instance of the cfc via createObject:

<cfscript>
    myObjectVar=createObject("component","myCFC");
    myReturnVar=myObjectVar.myCFCFunctionCall(arguments in here);
</cfscript>

Or something like that.

Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

Webmaster
04-22-2007 @ 11:59 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

You can include this on your application.cfm as follows:


<cfinclude template="udfs.cfm" />



Then create a file:
udfs.cfm


Put this code in it:

<cffunction name="dbQuery" output="false">

   <cfargument name="datasource" type="string" required="true" />
   <cfargument name="sqlCode" type="string" required="true" />

  <cfquery name="qQuery" datasource="#arguments.datasource#">
    #preserveSingleQuotes(arguments.sqlCode)#
  </cfquery>

  <cfreturn qQuery />

</cffunction>



Now you have a UDF you can call via CFScript...

so you can do this:


<cfscript>
  qQueryName = dbQuery(request.datasource, 'SELECT * FROM MyTable');

</cfscript>


you can do that with any tag that CFScript can't support.. does that make sense?


Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

This message was edited by Webmaster on 4-23-07 @ 12:00 AM

Lossed
04-23-2007 @ 12:18 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

You little ripper.
Cheers ears. Smile

Lossed
04-23-2007 @ 12:30 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 1095
Joined: Apr 2004

hmmmm...1st thought: load it via onRequest() method of Application.cfc- I mean, seeing how I'm banging my head against Application.cfc, a few more head injuries won't matter much.
2nd thought: why not load it into a persitent scope like application via onApplicationStart() so that it doesn't have to be called every page request, rather it's sitting in memory just rearing to go.
3rd thought: will access to it be single-threaded if it's in the application scope creating a bottleneck?
4th thought: just call it on every page I will need it, but given how much I like cfscript, it willprobably end up back in the onRequest method of Application.cfc.

Is there anything else I should be considering before I race off and convert tags over to cfscript?

Lossed
---------------------------
When the only tool you have is a hammer, everything looks like a nail Smile
-----------------------------

Webmaster
04-23-2007 @ 10:44 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

UDF's is one of those things that i tend to not include into any scope; since technically its inline code that is server based. So I would put it on the "onRequestStart" is you are using app.cfc (otherwise just include it).

Here is what I tend to put in the udf file myself... (note I provided the query example already; here are some other ones i use).

<!--- same as cflocation --->
<cffunction name="redirect">
     <cfargument name="redirectURL" type="string">
     <cflocation url="#redirectURL#" addtoken="no">
</cffunction>

<!--- same as cfabort --->
<cffunction name="abort">
     <cfabort>
</cffunction>

<!--- same as cfdump --->
<cffunction name="dump">
     <cfargument name="dumpVar" type="any">
     <cfdump var="#dumpVar#">
</cffunction>

<!--- same as cfparam --->
<cffunction name="param">
     <cfargument name="varname" type="any">          
     <cfscript>
          var value = "";     
          if(arrayLen(Arguments) gt 1) value = Arguments[2];
          if(not isDefined(varname)) setVariable(varname,value);
          return evaluate(varname);
     </cfscript>
</cffunction>

<!--- same as cfinclude --->
<cffunction name="include" output="true" returnType="any">
     <cfargument name="template" type="string" required="true">
     <cfinclude template="#template#">
</cffunction>

<!--- same as cfwddx --->
<cffunction name="wddx">     
     <cfargument name="action" type="any">
     <cfargument name="input" type="any">
     <cfwddx action="#action#" input="#input#" output="output">
     <cfreturn output>
</cffunction>

So that is a small library of what I tend to run!

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

This message was edited by Webmaster on 4-23-07 @ 10:45 AM

SirRawlins
04-23-2007 @ 11:52 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 951
Joined: Mar 2006

Hehe, There are also a whole stack of ORM Framrworks out there (this'll be in your next oop class bear) which can you use for database interaction.

I've been using 'Reactor' alot recently which is excelent, all sorts of neat toys, one of which is OO based database interaction, not just from the point of view of building all your DAO and Gateway objects, you can actualy build dynamic query objects using cfset of cfscript blocks, its really powerfull stuff.

http://trac.reactorframework.com/

Might be worth you taking a looksy.

Rob

GrowlyBear
04-23-2007 @ 12:04 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1314
Joined: May 2004

Maulin yur link don't work.

~~~~~~~~~~~~~~~~~~~
CF Blogger
http://www.cfblogger.com

SirRawlins
04-23-2007 @ 3:15 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 951
Joined: Mar 2006

Oh, fiddle sticks.

It must be down for the moment, THAT is definatly the right link for the site, perhaps stick it in your links list untill Doug can get it up and running again. It really is fantastic stuff.

Rob

PAGE: 1 2

Website Designed and Developed by Pablo Varando.