2

I'm attempting to build a method call from strings that have been passed into an object that refer to another object.

normally when calling an object we write the code like this:

application.stObj.oNewsBusiness.getNews(argumentCollection=local.stArgs);

However what I have done is created an array that contains the object name, the method name and the argument collection.

<cfscript>
local.stArgs = {};
local.stArgs.nNewsID = 19;
local.stArgs.sAuthor = "John";

local.aData = [];
local.aData[1] = local.stArgs;
local.aData[2] = "stObj.oNewsBusiness";
local.aData[3] = "getNews";
</cfscript>

however i am struggling to recombine all this to be a method call.

UPDATE using suggestion but still with issue

While cfinvoke seems to work for:

<cfinvoke component="#application.stObj.oNewsBusiness#" method="#local.sMethod#" argumentcollection="#local.stArgs#" returnvariable="local.qData"></cfinvoke>

it doesn't work when doing something like:

<cfscript>
local.stArgs = local.aData[1];
local.sObject = local.aData[2];
local.sMethod = local.aData[3];
</cfscript>
<cfinvoke component="application.#local.sObject#" method="#local.sMethod#" argumentCollection="#local.stArgs#" returnvariable="local.qData"></cfinvoke>

it generates an error:

Could not find the ColdFusion component or interface application.stObj.oNewsBusiness

4

3 に答える 3

7

CFInvoke は通常、動的メソッド呼び出しを処理するために使用されます。

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0a.html

CFInvoke には argumentcollection 属性があるため、慣れ親しんだ方法で引数を渡すことができます。

于 2012-06-14T13:33:56.537 に答える
2

ダンは正しいです CFInvoke が進むべき道です

<cfinvoke component="#mycomponentname#" method="get"  arg1="#arg1#" arg2="#arg2#" arg3=..>
于 2012-06-14T13:47:36.237 に答える
0
<cfinvoke component="application.#local.sObject#" method="#local.sMethod#"argumentCollection="#local.stArgs#" returnvariable="local.qData"></cfinvoke>

コンポーネント変数の周りに # 記号がないため、更新からは機能しません。

あなたができる

<cfset local.componentName = "application." & local.sObject>
<cfinvoke component="#local.componentName#" method="#local.sMethod#"argumentCollection="#local.stArgs#" returnvariable="local.qData"></cfinvoke>

おそらく、アプリケーションを結合するインラインの方法があります。cfinvoke呼び出しの変数を使用していますが、頭の中でわかりません。

編集:ダン・ウィルソンのコメントは、インラインの方法でそれをより良くします。

于 2012-06-14T14:57:59.193 に答える