【发布时间】:2011-07-11 12:48:20
【问题描述】:
我正在尝试使用 ColdFusion(版本 7.0.2.142559)将 CSV 文件加载到数组中。现在我收到以下错误:
coldfusion.runtime.Struct 类型的标量值不能分配给二维 ColdFusion 数组。 ColdFusion 二维数组只能保存一维 ColdFusion 数组和 Java List 对象。
我的 CSV 文件是以这种格式设置的:
a,b
c,d
e,f
这是我第一次使用 ColdFusion,所以我可能有一些我看不到的简单语法错误。代码如下。
<!--- get the current full path of the current --->
<cfset currentPath = getCurrentTemplatePath()>
<cfset currentDirectory = getDirectoryFromPath(currentPath)>
<!--- get and read the CSV-TXT file --->
<cffile action="read" file="#currentDirectory#/smalltest.csv" variable="csvfile">
<!--- create a new array --->
<cfset array=ArrayNew(2)>
<!--- loop through the CSV-TXT file on line breaks and insert into database --->
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">
<cfset array[#index#][1]=#listgetAt('#index#',1, ',')#>
<cfset array[#index#][2]=#listgetAt('#index#',2, ',')#>
</cfloop>
<cfdump var=#array#>
奖励:
附带说明一下,如果有某种方法可以从 ColdFusion 中调用 PHP 文件,我会节省很多时间,因为我已经在 PHP 中完成了整个脚本(这只是一小部分)。我阅读了有关 ColdFusion 自定义标签的信息(标签 <cf_php> 对我来说是完美的)但管理员说不,因此我必须使用 ColdFusion 或找到某种方法通过 ColdFusion 呈现 PHP。框架、JavaScript 或 <cfhttp> 标记都是我认为可能有用的东西......如果你有想法,请告诉我。
【问题讨论】:
-
如果你能解释一下你现有的 PHP 脚本在加载 CSV 数组后做了什么,我们可能会告诉你是否可以从 CF 调用你的 PHP 脚本。
-
@Anthony PHP 脚本从 CSV 文件中获取信息并以某种方式(基于 URL 中传递的变量)对其进行排序,然后将其输出到 HTML 表。 @Henry
<cf_php>似乎是个好主意,如果我的服务器支持自定义标签,但事实并非如此。不然我为什么要忘记<cf_php>>
标签: php arrays coldfusion csv multidimensional-array