Solved

Createobject - cfinvoke

Posted on 2012-03-22
7
333 Views
Last Modified: 2012-03-22
Hello experts.
I need help to replace the following createobject with cfinvoke.
cfm
<cfset objsheduletask = createobject("component","com.scheduletasks").init(request.dsn)/>
<cfset objsheduletask.fsendundelivered(request.homeurl)/>

cfc
   <cffunction name="init" access="public" output="false" returntype="any">
        <cfargument name="dsn" type="string" required="true">
        <cfset variables.dsn = arguments.dsn>
        <cfreturn this>
   </cffunction>
   <cffunction name="fsendundelivered" returntype="boolean" access="public">
     <cfargument name="homeurl" type="string" required="yes">
 <cfquery name="....." datasource="#variables.dsn#">
.....
     
     <cfreturn true>
   </cffunction>

I could use:
cfm.
<cfinvoke component="com.scheduletasks" method="fsendundelivered">
 <cfinvokeargument name="homeurl" value="#request.homeurl#" >
</cfinvoke>
cfc
<cffunction name="fsendundelivered" returntype="boolean" access="public">
     <cfargument name="homeurl" type="string" required="yes">
      <cfquery name="....." datasource="#request.dsn#">
      .......
     <cfreturn true>
   </cffunction>
Is this correct?
Is there any better way?
0
Comment
Question by:Panos
7 Comments
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 37752056
here u should should

 <cfinvokeargument name="homeurl" value="#request.homeurl#" >

rest i m not sure what u are asking abt
0
 
LVL 2

Author Comment

by:Panos
ID: 37752078
Hi myselfrandhawa
I did correct this the same time you posted your comment.


Using the createobject i use the init function to set the dsn.
Using cfinvoke i have to delete the init function and use the request.dsn value.

I'm asking if i do this right
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 450 total points
ID: 37752282
Nothing technically wrong with the way you have it. But using a #request# variable makes the cfc slightly less modular.

Is there any better way?

If you're sure the component is stateless, and not tied to a specific session, yeah. Whichever you're using it's better to create stateless components once (in OnApplicationStart). Then store them in your application scope.  Using your original init() method:

       <cfinvoke component="com.scheduletasks" method="init"
                   dsn="#request.dsn" returnVariable="theObject" />
        <cfset application.scheduleTasks = theObject >

Then when you need to call one of the functions use:

    <cfinvoke component="#application.scheduleTasks#" method="fsendundelivered">
          <cfinvokeargument name="homeurl" value="#request.homeurl#" >
     </cfinvoke>

Just make sure ALL of your function variables are properly var scoped. Otherwise you'll have threading problems.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 50 total points
ID: 37752347
I'm curious why the change from createObject to cfinvoke.  To me createobject is a cleaner, more intuitive style and easier to assign to an application scope


<cfset application.sheduleTasks = createobject("component","com.scheduletasks").init(request.dsn)/>

Why would you want to change away from it?  (Other than a person preference to cfinvoke?)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37752406
Possible hosting restriction? Though my preference is createObject too..
0
 
LVL 2

Author Comment

by:Panos
ID: 37752471
Hi agx and gdemaria
Thank you for your posts.
Agx is right . There is a hosting restriction when i use createobject edit a scheduletask.
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 37752581
Thank you
regards panos
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question