2012-07-04 37 views
0

我試圖在CF 8.0.1,但失敗。我想自定義的值傳遞給自定義標籤,就像這樣:ColdFusion自定義標籤調用cfmail astibuteCollection並拋出錯誤

<cf_call ckmail="#{to='[email protected]',from='[email protected]',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}#"> 

在自定義標籤call.cfm我有以下幾點:

<cfparam name="attributes.ckmail" default=""> 
<cfmail attributecollection = "#attributes.ckmail#"> 

我得到的錯誤是:

在塔18的ColdFusion第11行中找到無效CFML構建體一直在尋找在以下文本:{

它在CF9中運行良好,但在CF8.0.1(或以前的版本)中,它失敗並顯示上述消息。


代碼更新爲7月18日的2012


我試着用丹的代碼,但現在我面臨着不同的問題,在我的自定義標籤,我使用這樣的

 <cfset emailSetting = StructNew()> 
    <!--- loop our query string values and set them in our structure ---> 
    <cfloop list="#attributes.ckmail#" index="key" delimiters=","> 
    <cfset emailSetting["#listFirst(key,'=')#"] = urlDecode(listLast(key,"="))> 
    </cfloop> 
    <cfdump var="#emailSetting#"><cfabort> 
     <cfmail attributecollection = "#emailSetting#"> 

以上是我在自定義標記中的設置,我從我的代碼中調用它作爲

 <cf_call ckmail="[email protected],[email protected],subject='Error reported', 
    server=mail.domain.com,[email protected],[email protected],type=html"> 

的錯誤現在我得到的是「SMTP」服務器沒有定義,

如果我添加的smtp細節cfadmin它的工作原理,可能是它忽略值在我輸入的字段,但它顯示的錯誤當沒有在cfadmin中定義的smtp設置時。

回答

0

您在ckmail屬性中使用了struct literal語法,我認爲這已經改變了CF8和CF9之間的行爲。我會嘗試以老式的方式創建一個結構體,看看它是否有效。

+0

所以使用Structnew()右邊,順便說一句,我傳遞它在自定義標記,所以有點混亂如何工作 – Misty

+0

它只會看起來像它不會有任何construtor語法 - 這一切提前完成。看看第一個答案 - 馬特的例子很清楚。 –

2

隱式結構應該像CF8.0.1一樣工作。

你當然也可以使用如下代碼使用structNew建立自己的結構()函數:

<cfset mailArgs    = StructNew() /> 
<cfset mailArgs.to   = '[email protected]' /> 
<cfset mailArgs.from  = '[email protected]' /> 
<cfset mailArgs.subject  = 'Error reported' /> 
<cfset mailArgs.mailserver = 'mail.domain.com' /> 
<cfset mailArgs.username = '1234' /> 
<cfset mailArgs.password = 'tested' /> 

<cf_call ckmail="#mailArgs#"> 

您可以發佈從ColdFusion的這裏更詳細的錯誤報告,以便我們可以幫你找錯誤的確切位置?或者你可以發佈更多的代碼?

+0

這是我從代碼中得到的詳細報告,當CF9執行這個過程時,我的困惑在於,而在CF8中它失敗了,我看到你已經以不同的方式聲明瞭一個Struct,然後將它傳遞給了cfmail標記,我希望它沿着自定義標籤傳遞,但做 不想單獨聲明,並再次在自定義標籤中使用上面的書面代碼:,我想通過上面的實際寫入,而不是評估它再次在這裏 – Misty

0

嗯......我想知道在自定義標記調用中,英鎊標誌是否對其他人來說很奇怪? Stucture符號通常是這樣的:

<cfset mystruct = {to='[email protected]',from='[email protected]',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}/> 

英鎊跡象會導致CF嘗試「做什麼」,以合併值(當你做<cfset z = #x+y#/>喜歡......但留給他們關允許CF「看」構造函數指示器(花括號)

但我不確定自定義標記在該實例中的行爲方式。您是否嘗試調用它像這樣:

<cf_call 
ckmail={to='[email protected]',from='[email protected]',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}/> 

或者做不到這一點 - 因爲已經建議 - 將它設置的時間提前爲:

<cfset args = {to='[email protected]',from='[email protected]',subject='Error reported',mailserver='mail.domain.com',username='1234',password='tested'}/> 

然後調用:

<cf_call ckmail="#args#"/> 

見如果有任何工作呃?

+0

我試着你說的在這裏,但仍然面臨着同樣的問題,我已經更新了我的問題,請檢查,這次我得到了一些不同的錯誤「smtp未定義」 – Misty