• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Individual CFCs using CFINVOKE

Contributor ,
Feb 21, 2007 Feb 21, 2007

Copy link to clipboard

Copied

A customer wants OOP like programming but his host doesn't allow objects. Is there anyway to make an objectlike thing using CFINVOKE?
TOPICS
Advanced techniques

Views

729

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2007 Feb 21, 2007

Copy link to clipboard

Copied

> his host doesn't allow objects.
Quite draconian. He must have meant cfobject, surely.

Is there anyway to make an objectlike thing
Cfinvoke only invokes components. You make component-objects and other objects usually with
- the tag cfobject
- the function createObject





Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

> his host doesn't allow objects.
Quite draconian. He must have meant cfobject, surely.

Is there anyway to make an objectlike thing
Cfinvoke only invokes components. You make component-objects and other
objects
usually with
- the tag cfobject
- the function createObject


It can also be done with <cfinvoke...>. This tag must call a function,
but if that function returns a reference to the object itself, then the
variable in the <cfinvoke...> tag can subsequently be used to call
methods on the object.

<cfcomponent...>
...
<cffunction name="init"...>
...
<cfreturn this>
</cffunction>
...
</cfcomponent>


<cfinvoke component="myCFC" method="init" returnVariable="objVar"/>

<cfdump var="#objVar#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

BKBK, despite your opinion of how things should be, there are many hosting companies that do not allow cfobject nor createobject. These 2 along with cfdirectory and cffile are seen as serious security risks.

Ian, interesting. So if I do this and then have it assigned to a variable like:
<cfset myObj1 = #objVar#>
it would work just like a cfobject. Just more lines of code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

<cfset myObj1 = #objVar#>
it would work just like a cfobject. Just more lines of code.

You don't even need that line. Just use objVar as you would a variable
created with <cfobject...> or createObject().

I.e.

<cfoutput>#objVar.aMethod()#</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

Yes, but I want to build different objects of the same class.

Like myObj1, myObj2 etc etc So I will need different instances.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

Like myObj1, myObj2 etc etc So I will need different instances.

Each of those would be a different <cfinvoke...> Just like they would
be different <cfobjects...> or createObjects().

<cfinvoke component="myCFC" method="init" returnVariable="myObj1">
<cfinvoke component="myCFC" method="init" returnVariable="myObj2">
<cfinvoke component="myCFC" method="init" returnVariable="myObj3">

All these methods are used to create instances of components, as best as
I know. If others use them in other ways I would love to hear about it.
I am still very much trying to wrap my old procedural head around the
object world.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

Ian and Dinghus,
You've misread my reaction. I maintain that it is quite draconian if, as Dinghus puts it, "his host doesn't allow objects". He may disallow some tags or functions, not objects. Without objects, Coldfusion MX reduces to the proverbial lead balloon.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

It [Dinghus' "objectlike thing"] can also be done with <cfinvoke...>.
I said so: cfinvoke for components, cfobject and createobject for objects in general. Remember that components remain just that, component-objects. They are not objects in the Java sense.





Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

If a host doesn't allow cfobject or createObject they are disallowing objects for our purposes. Obviously since MX is Java based, objects are used. But you missed the whole point or are just not comprehending what is being discussed. CFMX is NOT an OO language and so all attempts to emulate one are not Java-like.
But if I can make a pseudo-object with CFINVOKE ... great. My primary purpose is served.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

If a host doesn't allow cfobject or createObject they are disallowing objects for our purposes.

No, he is disallowing the use of the tag cfobject and the function createobject. As you yourself have discovered, there are quite a number of entities in Coldfusion that we call objects, but that are not created with cfobject or createobject. A component is one of them. When you say the host "doesn't allow objects" you imply he doesn't allow components either. It is not wise to blanket everything under objects. You will see why in a moment.

But you missed the whole point or are just not comprehending what is being discussed. CFMX is NOT an OO language and so all attempts to emulate one are not Java-like. But if I can make a pseudo-object with CFINVOKE ... great. My primary purpose is served.

I don't think there's a point I missed or misunderstood. Coldfusion MX, particularly the recent versions, are more Java than you think. It goes beyond what you call "java-like" or "pseudo".

There are ways of approaching objects without <cfobject> and createobject(). here are some:

1) Coldfusion MX pages are essentially J2EE servlets. As such, a Coldfusion page has a Java PageContext object. You can use it to run servlets and JSPs.

2) objects by means of Flash or Flex (if available)

2) run java by means of cfexecute

4) deploy JAR files by means of the cfimport tag

It is, of course, inconvenient for a host to disable cfobject and createobject. However, that should not condition one into believing that one can no longer work with objects. Your imagination will cut corners.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 22, 2007 Feb 22, 2007

Copy link to clipboard

Copied

I was right, you missed the point or are intentionally ignoring it. Whatevers.

Oh, and if they are disallowing cfobject/createobject do you really believe they allow cfexecute? Or any other thing to do with objects?

I'm sure I could beat my head against the wall some more but it isn't worth my time. So carry on.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2007 Feb 23, 2007

Copy link to clipboard

Copied

LATEST
I was right, you missed the point or are intentionally ignoring it. Whatevers.
Why do you repeat that I miss the point without mentioning the point I miss.

Oh, and if they are disallowing cfobject/createobject do you really believe they
allow cfexecute? Or any other thing to do with objects?

Yes, it is possible. There is only one way to find out. Contact the host.

You speak as if there is one security button which, when pressed, disables all of Coldfusion's object functionality. The host has some choices to make. It usually comes down to a decision on a tag by tag and function by function basis, depending on experience and whim.

I would agree with you that it is unlikely for cfexecute to be enabled while cfobject and createobject are disabled. My point is that cfexecute is just one more object functionality hosts, and you, have to think about. Now, there is a reversal in the argument. We should not forget that when the host disables a tag or function, it is usually to protect us. I wouldn't use a shared host who allows cfexecute on a shared Windows server.

Look around. You will find the other functionalities I mentioned enabled on hosts where cfobject and createobject are disabled. A finesse in the recent version of MX7 enables the host to selectively disable createobject for Java, Com and Corba objects, but to allow it for components and webservices.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation