电导法测定海水氯化物

tech2024-04-20  99

电导法测定海水氯化物

Recently in the SitePoint ColdFusion forums there was a nice little discussion about CFC’s and how everyone who explains them or teaches them throws in a lot of buzzwords which does more to confuse people then to help them along. Now I know this happens because I’m guilty of it as well as a lot of other seasoned ColdFusion developers. So hopefully with this post I can help move those who are interested but unsure about CFC’s into this wonderful world.

最近,在SitePoint ColdFusion论坛上 ,有关CFC的讨论很少 ,每个解释或教导它们的人如何用大量的流行语来表达,这更多的是使人们困惑,然后帮助他们。 现在我知道发生了这种情况,因为我以及其他许多经验丰富的ColdFusion开发人员都对此感到内gui。 因此,希望通过这篇文章,我可以帮助那些对CFC感兴趣但不确定的人进入这个美好的世界。

So what is a CFC? First off a CFC is actually called a ColdFusion Component and at its most simple terms it’s just a ColdFusion template (aka a ColdFusion page or file) but instead of a .cfm or .cfml extension it has a .cfc extension.

那么什么是CFC? 首先,CFC实际上被称为ColdFusion组件,从最简单的术语来说,它只是一个ColdFusion模板(又称ColdFusion页面或文件),但不是.cfm或.cfml扩展名,而是具有.cfc扩展名。

Now just because a file has a .cfc extension on it doesn’t make it a CFC right away. Once you have your .cfc file created you do have to write some code. Typically a CFC is made up of 2 or 3 basic parts. The first part is the actually CFC tags and they look something like this:

现在,仅仅因为文件具有.cfc扩展名并不能立即使其成为CFC。 创建.cfc文件后,您必须编写一些代码。 CFC通常由2或3个基本部分组成。 第一部分是实际的CFC标签,它们看起来像这样:

<cfcomponent displayname="Greeting" hint="I'm a greeting CFC"> </cfcomponent>

There is only one tag which makes a CFC and that is the CFComponent tag, which requires both an opening and closing tag. Now from this point you can add some code inside these tags or you can leave it blank, which is left blank will give you a blank CFC. You’ll notice that my CFComponent tag has two additional attributes displayname and hint. These are descriptive attribute in that they don’t DO anything but they DO describe the CFC. The displayname attribute is the name which shows up when ColdFusion auto generates documentation for a CFC and the hint is the description. We’ll talk more about documentation later though :)

只有一个标签可以制作CFC,也就是CFComponent标签,它需要打开和关闭标签。 现在,您可以在这些标签中添加一些代码,也可以将其保留为空白,将其保留为空白将得到一个空白的CFC。 您会注意到,我的CFComponent标记还有两个附加属性displayname和hint 。 这些是描述性属性,因为它们不执行任何操作,但它们确实描述了CFC。 displayname属性是当ColdFusion自动生成CFC文档时显示的名称, 提示是描述。 我们稍后再讨论文档:)

So what can go inside these CFComponent tags? Pretty much any ColdFusion tags you normally use can be used inside the CFComponent tags. Typically though a CFC is a collection of functions, using the CFFunction tag, and sometimes properties, using the CFProperty tag.

那么这些CFComponent标签里面可以放什么呢? 您通常使用的几乎所有ColdFusion标签都可以在CFComponent标签内使用。 通常,尽管CFC是使用CFFunction标签的功能集合,有时使用CFProperty标签的属性集合。

Now I’m sure you’ve seen the CFFunction tag and if you’ve done any extensive development with CF MX (version 6) or later you’ve used your fair share of CFFunction tags. For CFC’s you use the same syntax as you would anywhere else in your code. For example if I wanted a function to return a general greeting for me I might write it as:

现在,我确定您已经看过CFFunction标签,并且如果您使用CF MX(第6版)或以后的版本进行了广泛的开发,则已经使用了相当一部分CFFunction标签。 对于CFC,您可以使用与代码中其他任何地方相同的语法。 例如,如果我想要一个函数为我返回一般问候,则可以将其编写为:

<cffunction name="getGreeting" output="false" returntype="string" description="Returns a greeting string"> <cfargument name="visitor" required="no" type="string" displayname="Visitor String" hint="The Visitors name"> <cfif IsDefined('arguments.visitor') AND Len(Trim(arguments.visitor))> <cfreturn 'Welcome ' & arguments.visitor & '! I hope you enjoy your stay.'> <cfelse> <cfreturn 'Welcome guest! Enjoy your visit and please come back soon.'> </cfif> </cffunction>

Now this code is a bit beefier so I’ve numbered each line so we can walk through it without me having to reprint it (and risk a cut and paste mistake!). So line 1 sets up our function with the CFFunction tag and within this tag I’ve used 4 attributes. The name attribute is the wording I’ll use to reference or call this function, in this case it’s called getGreeting. Next I set the output attribute to false which tells ColdFusion to treat this function as if it was inside a CFSilent tag, thereby forcing only the text I specify in the CFReturn tag to be output when the function is called. If I set the output to true then any code I had inside this function (including HTML) would show up when this function was processed. 99% of the time you want to make sure you set the output to false unless you have a reason for HTML and CFML to be processed and shown without the use of a cfreturn tag. (I haven’t come across this yet, but I’m sure someone has). The next attribute is the returntype which I’ve set to string. Setting a return type is useful because it allows ColdFusion to error check the data which a particular function returns. So if i accidentally returned an array, or query ColdFusion would error out telling me that they type of data returned from this function was not of type string. It’s very rare that my functions actually return anything other than what i tell it to but when you get into complex CFC’s which are returning all kinds of data types setting the return type can be very helpful. Now you don’t HAVE to set a returntype but if CFC’s and Functions are new to you I’d recommend you do until you have a solid grasp of what exactly is happening and why. Ok the last attribute we set is the description and this is just used to describe to a fellow developer what is going on, and if you use ColdFusion to create your docs (more on that later) this will be output in those docs, so always try to describe your functions.

现在这段代码更加强大,因此我已经为每一行编号,因此我们可以遍历它而不必重印它(并且可能会出现剪切和粘贴错误!)。 因此,第1行使用CFFunction标签设置了我们的功能,在此标签中,我使用了4个属性。 name属性是我将用来引用或调用此函数的措辞,在这种情况下,它称为getGreeting。 接下来,我将输出属性设置为false ,这告诉ColdFusion将此函数当作在CFSilent标记内一样对待,从而在调用该函数时仅强制输出在CFReturn标记中指定的文本。 如果将输出设置为true,则处理此函数时,将显示此函数中包含的所有代码(包括HTML)。 除非您有理由在不使用cfreturn标记的情况下处理和显示HTML和CFML,否则有99%的时间要确保将输出设置为false。 (我还没有遇到过,但是我敢肯定有人知道)。 下一个属性是我设置为string的returntype 。 设置返回类型非常有用,因为它允许ColdFusion对特定函数返回的数据进行错误检查。 因此,如果我不小心返回了一个数组,或者查询ColdFusion会出错,告诉我它们从此函数返回的数据类型不是字符串类型。 我的函数实际上返回的不是我所告诉的内容,这非常罕见,但是当您遇到复杂的CFC(返回各种数据类型)时,设置返回类型会非常有帮助。 现在,您不必设置返回类型,但是如果您对CFC和功能不熟悉,那么我建议您这样做,直到您对实际发生的情况及其原因有扎实的了解。 好的,我们设置的最后一个属性是description ,它只是用来向开发人员描述正在发生的事情,如果您使用ColdFusion创建文档(稍后再介绍),它将在这些文档中输出,因此始终尝试描述您的功能。

Line 2 is a CFArgument tag. Functions have the ability to take in data and then process or do something with that data, this passed in data is referred to as a argument and functions can have multiple arguments passed in. The CFArgument tag above consists of 5 attributes. the name attribute is the name of the argument being passed in, in this case it’s visitor. Next we have a required attribute which tells ColdFusion if this argument is required for the function to work properly. In this case we have set the value of the required attribute to no so we could call this function and not pass in any arguments. Next we have the type attribute which tells ColdFusion what kind of data this argument is going to be. Again by specifying a type ColdFusion will check the passed in data and if it’s not of the specified type it will return an error. In this case we told our function that visitor will be of type string so it will allow just about anything in. The last two attributes displayname and hint are again used to help my fellow developers know what is going on and also for documentation.

第2行是CFArgument标记。 函数具有接收数据然后处理或对该数据进行处理的能力,此传入的数据称为自变量,函数可以具有多个自变量。上面的CFArgument标记包含5个属性。 name属性是要传入的参数的名称,在本例中为visitor 。 接下来,我们有一个required属性,该属性告诉ColdFusion函数正常工作是否需要此参数。 在这种情况下,我们将required属性的值设置为no,因此我们可以调用此函数而不传递任何参数。 接下来,我们具有type属性,该属性告诉ColdFusion该自变量将是哪种数据。 再次通过指定类型ColdFusion将检查传入的数据,如果不是指定类型,则将返回错误。 在这种情况下,我们告诉我们的函数,访问者将是字符串类型,因此它将允许任何输入。最后两个属性displayname和hint再次用于帮助我的开发人员了解正在发生的事情以及用于文档。

Line 3 starts our if statement where we check to see if my visitor argument was passed in our not. When using functions all variables passed in are in the arguments scope which is a scope only accessible by code inside the opening and closing function tags. Here i use the IsDefined function to see if the variable exists and if it does exist then the next bit of code to execute is my Len() and Trim() functions. I’ve nested the trim function inside the len function so that any white space or carriage returns in the visitor variable data will be stripped out and i will only get a length value for the actual data passed in the string. By doing the trim and then the len i can ensure that a bunch of blank spaces, tabs, or returns weren’t sent in and that i actually have a string of usable data. I could have written this bit of code as Len(Trim(arguments.visitor)) GT 1 and it would have the same effect as Len(Trim(arguments.visitor)) since the later will return either zero or some positive number.

第3行从if语句开始,在该语句中检查我的visitor参数是否传入了not。 使用函数时,所有传入的变量都在自变量范围中,该范围只能由打开和关闭功能标签内的代码访问。 在这里,我使用IsDefined函数查看变量是否存在,如果确实存在,则下一个要执行的代码是我的Len()和Trim()函数。 我将trim函数嵌套在len函数中,以便将访问者变量数据中的所有空格或回车符都去除掉,并且我只会获得字符串中传递的实际数据的长度值。 通过修剪,然后修剪len,我可以确保未发送一堆空格,制表符或返回值,并且实际上我有一串可用数据。 我可以将这段代码写为Len(Trim(arguments.visitor))GT 1 ,它的作用与Len(Trim(arguments.visitor))相同,因为后者将返回零或一些正数。

OK line 4 has a CFReturn tag and you should notice there are no attributes here. the CFReturn tag takes an expression, in this case a string, and it’s this expression which is returned by the function. Here I’ve typed in a little greeting and used the & symbol to concatenate two strings around whatever data was passed into my function via the visitor variable.

OK行4具有CFReturn标记,您应该注意到这里没有属性。 CFReturn标记采用一个表达式(在这种情况下为字符串),并且此表达式由函数返回。 在这里,我输入了一些问候,并使用&符号将通过visitor变量传递给函数的任何数据周围的两个字符串连接在一起。

line 5 is our cfelse statement so if arguments.visitor did not exist OR the length of the value for arguments.visitor after it was trimmed was 0 then line 6 will be executed.

第5行是我们的cfelse语句,因此,如果arguments.visitor不存在或者被修剪后的arguments.visitor的值的长度为0,则将执行第6行。

line 6 is another CFReturn tag but this time it just a simple text sentence with no variables being concatenated like we saw on line 4.

第6行是另一个CFReturn标记,但这一次它只是一个简单的文本语句,没有变量的连接,就像在第4行看到的那样。

Line 7 closed out our CFIF block and line 8 will close out our CFFunction tag. So if we put our component code with our function code it should look like:

第7行关闭了CFIF块,第8行关闭了CFFunction标签。 因此,如果将组件代码和功能代码放在一起,它应该看起来像:

<cfcomponent displayname="Greeting" hint="I'm a greeting CFC"> <cffunction name="getGreeting" output="false" returntype="string" description="Returns a greeting string"> <cfargument name="visitor" required="no" type="string" displayname="Visitor String" hint="The Visitors name"> <cfif IsDefined('arguments.visitor') AND Len(Trim(arguments.visitor))> <cfreturn 'Welcome ' & arguments.visitor & '! I hope you enjoy your stay.'> <cfelse> <cfreturn 'Welcome guest! Enjoy your visit and please come back soon.'> </cfif> </cffunction> </cfcomponent>

So now you have a very basic CFC. You can copy this text into your editor of choice if you want and save the file as greeting.cfc. So now that you have this CFC what can you do with it? how do you call it? what’s the point? All of these are great questions but you’re going to have to wait at least 24 – 48 hours to get the answer. Why? Because I’m writing this at 11pm on Thanksgiving night and i have plans to get up at 3 AM in hopes to score myself a Nintendo Wii. Yes i’m a gamer and the last time i stood in line for the Wii i was lucky enough to find out i was number 29 in line for 26 units, a fate i hope not to repeat! So look for my next post 24 hours after this one goes live (not sure when that will be since my Internet connection is flaky out here).

所以现在您有了一个非常基本的CFC。 您可以根据需要将此文本复制到所选的编辑器中,并将文件另存为greeting.cfc。 那么,既然您拥有该CFC,该怎么办? 你怎么称呼它? 重点是什么? 所有这些都是很好的问题,但是您至少需要等待24-48小时才能获得答案。 为什么? 因为我在感恩节之夜的晚上11点写这篇文章,并且我计划在凌晨3点起床,希望能给自己打个任天堂Wii。 是的,我是一名游戏玩家,上次我为Wii排队时,我很幸运地发现我在26个单位中排在第29位,我希望不再重复这种命运! 因此,请在此消息发布24小时后查找我的下一条消息(不知道何时发布,因为我的互联网连接不稳定)。

翻译自: https://www.sitepoint.com/cfcs-for-the-common-developer/

电导法测定海水氯化物

相关资源:高温燃烧水解-离子色谱法同时测定煤中氟和氯
最新回复(0)