summaryrefslogtreecommitdiffhomepage
path: root/es-es/coldfusion-es.html.markdown
blob: 0429dd11180e8955b4114bcb1396b13343865280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
---
language: coldfusion
filename: learncoldfusion-es.cfm
contributors:
    - ["Wayne Boka", "http://wboka.github.io"]
    - ["Kevin Morris", "https://twitter.com/kevinmorris"]
translators:
    - ["Ivan Alburquerque", "https://github.com/AlburIvan"]
lang: es-es
---

ColdFusion es un lenguaje de scripting para desarrollo web.
[Lea más aquí](http://www.adobe.com/products/coldfusion-family.html)

### CFML
_**C**old**F**usion **M**arkup **L**anguage_  
ColdFusion comenzó como un lenguaje basado en etiquetas. Casi toda la funcionalidad está disponible usando etiquetas.

```cfm
<em>Se han proporcionado etiquetas HTML para facilitar la lectura.</em>

<!--- Los comentarios comienzan con "<!---" y terminan con "--->" --->
<!---
    Los comentarios
    también
    pueden ocupar
    multiples líneas
--->

<!--- Las etiquetas CFML tienen un formato similar a las etiquetas HTML. --->
<h1>Variables simples</h1>
<!--- Declaración de variables: las variables son débilmente tipadas, similar a javascript --->
<p>Set <b>miVariable</b> to "miValor"</p>
<cfset miVariable = "miValor" />
<p>Set <b>miNumero</b> to 3.14</p>
<cfset miNumero = 3.14 />

<!--- Mostrando datos simples --->
<!--- Use <cfoutput> para valores simples como cadenas, números y expresiones --->
<p>Muestra <b>miVariable</b>: <cfoutput>#miVariable#</cfoutput></p><!--- miValor --->
<p>Muestra <b>miNumero</b>: <cfoutput>#miNumero#</cfoutput></p><!--- 3.14 --->

<hr />

<h1>Variables complejas</h1>
<!--- Declarar variables complejas. --->
<!--- Declarar una matriz de 1 dimensión: literal o notación de corchete --->
<p>Establecer <b>miArreglo1</b> en una matriz de 1 dimensión utilizando la notación literal o de corchete</p>
<cfset miArreglo1 = [] />
<!--- Declarar una matriz de 1 dimensión: notación de función --->
<p>Establecer <b> miArreglo2 </b> en una matriz de 1 dimensión usando la notación de funciones</p>
<cfset miArreglo2 = ArrayNew(1) />

<!--- Salida de variables complejas. --->
<p>Contenidos de <b>miArreglo1</b></p>
<cfdump var="#miArreglo1#" /> <!--- Un objeto de matriz vacío --->
<p>Contenidos de <b>miArreglo2</b></p>
<cfdump var="#miArreglo2#" /> <!--- Un objeto de matriz vacío --->

<!--- Los operadores --->
<!--- Aritméticos --->
<h1>Operadores</h1>
<h2>Aritméticos</h2>
<p>1 + 1 = <cfoutput>#1 + 1#</cfoutput></p>
<p>10 - 7 = <cfoutput>#10 - 7#<br /></cfoutput></p>
<p>15 * 10 = <cfoutput>#15 * 10#<br /></cfoutput></p>
<p>100 / 5 = <cfoutput>#100 / 5#<br /></cfoutput></p>
<p>120 % 5 = <cfoutput>#120 % 5#<br /></cfoutput></p>
<p>120 mod 5 = <cfoutput>#120 mod 5#<br /></cfoutput></p>

<hr />

<!--- Comparación --->
<h2>Comparación</h2>
<h3>Notación estándar</h3>
<p>Is 1 eq 1? <cfoutput>#1 eq 1#</cfoutput></p>
<p>Is 15 neq 1? <cfoutput>#15 neq 1#</cfoutput></p>
<p>Is 10 gt 8? <cfoutput>#10 gt 8#</cfoutput></p>
<p>Is 1 lt 2? <cfoutput>#1 lt 2#</cfoutput></p>
<p>Is 10 gte 5? <cfoutput>#10 gte 5#</cfoutput></p>
<p>Is 1 lte 5? <cfoutput>#1 lte 5#</cfoutput></p>

<h3>Notación alternativa</h3>
<p>Is 1 == 1? <cfoutput>#1 eq 1#</cfoutput></p>
<p>Is 15 != 1? <cfoutput>#15 neq 1#</cfoutput></p>
<p>Is 10 > 8? <cfoutput>#10 gt 8#</cfoutput></p>
<p>Is 1 < 2? <cfoutput>#1 lt 2#</cfoutput></p>
<p>Is 10 >= 5? <cfoutput>#10 gte 5#</cfoutput></p>
<p>Is 1 <= 5? <cfoutput>#1 lte 5#</cfoutput></p>

<hr />

<!--- Estructuras de Control --->
<h1>Estructuras de Control</h1>

<cfset miCondicion = "Prueba" />

<p>Condición a probar: "<cfoutput>#miCondicion#</cfoutput>"</p>

<cfif miCondicion eq "Prueba">
    <cfoutput>#miCondicion#. Estamos probando.</cfoutput>
<cfelseif miCondicion eq "Producción">
    <cfoutput>#miCondicion#. Procede con cuidado!!!</cfoutput>
<cfelse>
    miCondicion es desconocido
</cfif>

<hr />

<!--- Bucles --->
<h1>Bucles</h1>
<h2>Bucle For</h2>
<cfloop from="0" to="10" index="i">
	<p>Index equals <cfoutput>#i#</cfoutput></p>
</cfloop>

<h2>Bucle For Each (Variables complejas)</h2>

<p>Establecer <b>miArreglo3</b> to [5, 15, 99, 45, 100]</p>

<cfset miArreglo3 = [5, 15, 99, 45, 100] />

<cfloop array="#miArreglo3#" index="i">
	<p>Index equals <cfoutput>#i#</cfoutput></p>
</cfloop>

<p>Establecer <b>myArray4</b> to ["Alpha", "Bravo", "Charlie", "Delta", "Echo"]</p>

<cfset myArray4 = ["Alpha", "Bravo", "Charlie", "Delta", "Echo"] />

<cfloop array="#myArray4#" index="s">
	<p>Index equals <cfoutput>#s#</cfoutput></p>
</cfloop>

<h2>Declaración Switch</h2>

<p>Establecer <b>miArreglo5</b> to [5, 15, 99, 45, 100]</p>

<cfset miArreglo5 = [5, 15, 99, 45, 100] />

<cfloop array="#miArreglo5#" index="i">
	<cfswitch expression="#i#">
		<cfcase value="5,15,45" delimiters=",">
			<p><cfoutput>#i#</cfoutput> es un múltiplo de 5.</p>
		</cfcase>
		<cfcase value="99">
			<p><cfoutput>#i#</cfoutput> es noventa y nueve.</p>
		</cfcase>
		<cfdefaultcase>
			<p><cfoutput>#i#</cfoutput> no es 5, 15, 45, or 99.</p>
		</cfdefaultcase> 
	</cfswitch> 
</cfloop>

<hr />

<h1>Conversión de tipos</h1>

<style>
	table.table th, table.table td {
		border: 1px solid #000000;
		padding: 2px;
	}
	
	table.table th {
		background-color: #CCCCCC;
	}
</style>

<table class="table" cellspacing="0">
	<thead>
		<tr>
			<th>Valor</th>
			<th>Como booleano</th>
			<th>Como número</th>
			<th>Como fecha</th>
			<th>Como cadena</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th>"Si"</th>
			<td>TRUE</td>
			<td>1</td>
			<td>Error</td>
			<td>"Si"</td>
		</tr>
		<tr>
			<th>"No"</th>
			<td>FALSE</td>
			<td>0</td>
			<td>Error</td>
			<td>"No"</td>
		</tr>
		<tr>
			<th>TRUE</th>
			<td>TRUE</td>
			<td>1</td>
			<td>Error</td>
			<td>"Yes"</td>
		</tr>
		<tr>
			<th>FALSE</th>
			<td>FALSE</td>
			<td>0</td>
			<td>Error</td>
			<td>"No"</td>
		</tr>
		<tr>
			<th>Número</th>
			<td>True si el número no es 0; False de lo contrario.</td>
			<td>Número</td>
			<td>Consulte &#34;Date-time values&#34; anteriormente en este capítulo.</td>
			<td>Representación de cadena del número (for example, &#34;8&#34;).</td>
		</tr>
		<tr>
			<th>Cadena</th>
			<td>Si representa una fecha y hora (ver la siguiente columna), se convierte al valor numérico del objeto de fecha y hora correspondiente. <br> Si es una fecha, hora o marca de tiempo ODBC (por ejemplo, "{ts '2001-06-14 11:30:13'}", o si se expresa en un formato de fecha u hora estándar de EE. UU., incluido al usar nombres de mes completos o abreviados, se convierte al valor de fecha y hora correspondiente. <br> Los días de la semana o la puntuación inusual dan como resultado un error. <br> Generalmente se permiten guiones, barras diagonales y espacios. </td>
			<td>Cadena</td>
		</tr>
		<tr>
			<th>Fecha</th>
			<td>Error</td>
			<td>El valor numérico del objeto fecha-hora.</td>
			<td>Fecha</td>
			<td>una marca de tiempo de ODBC.</td>
		</tr>
	</tbody>
</table>

<hr />

<h1>Componentes</h1>

<em>Código de referencia (las funciones deben devolver algo para admitir IE)</em>
```

```cfs
<cfcomponent>
	<cfset this.hola = "Hola" />
	<cfset this.mundo = "Mundo" />

	<cffunction name="sayHhola">
		<cfreturn this.hola & ", " & this.mundo & "!" />
	</cffunction>
	
	<cffunction name="setHhola">
		<cfargument name="newHola" type="string" required="true" />
		
		<cfset this.hola = arguments.newHola />
		 
		<cfreturn true />
	</cffunction>
	
	<cffunction name="setMundo">
		<cfargument name="newMundo" type="string" required="true" />
		
		<cfset this.mundo = arguments.newMundo />
		 
		<cfreturn true />
	</cffunction>
	
	<cffunction name="getHola">
		<cfreturn this.hola />
	</cffunction>
	
	<cffunction name="getMundo">
		<cfreturn this.mundo />
	</cffunction>
</cfcomponent>

<cfset this.hola = "Hola" />
<cfset this.mundo = "Mundo" />

<cffunction name="sayHola">
	<cfreturn this.hola & ", " & this.mundo & "!" />
</cffunction>

<cffunction name="setHola">
	<cfargument name="newHola" type="string" required="true" />
	
	<cfset this.hola = arguments.newHola />
	 
	<cfreturn true />
</cffunction>

<cffunction name="setMundo">
	<cfargument name="newMundo" type="string" required="true" />
	
	<cfset this.mundo = arguments.newMundo />
	 
	<cfreturn true />
</cffunction>

<cffunction name="getHola">
	<cfreturn this.hola />
</cffunction>

<cffunction name="getMundo">
	<cfreturn this.mundo />
</cffunction>


<b>sayHola()</b>
<cfoutput><p>#sayHola()#</p></cfoutput>
<b>getHola()</b>
<cfoutput><p>#getHola()#</p></cfoutput>
<b>getMundo()</b>
<cfoutput><p>#getMundo()#</p></cfoutput>
<b>setHola("Hola")</b>
<cfoutput><p>#setHola("Hola")#</p></cfoutput>
<b>setMundo("mundo")</b>
<cfoutput><p>#setMundo("mundo")#</p></cfoutput>
<b>sayHola()</b>
<cfoutput><p>#sayHola()#</p></cfoutput>
<b>getHola()</b>
<cfoutput><p>#getHola()#</p></cfoutput>
<b>getMundo()</b>
<cfoutput><p>#getMundo()#</p></cfoutput>
```

### CFScript
_**C**old**F**usion **S**cript_  
En los últimos años, el lenguaje ColdFusion ha agregado sintaxis de script para simular la funcionalidad de etiquetas. Cuando se utiliza un servidor CF actualizado, casi todas las funciones están disponibles mediante la sintaxis de script.

## Otras lecturas

Los enlaces que se proporcionan a continuación son solo para comprender el tema, siéntase libre de buscar en Google y encuentrar ejemplos específicos.

1. [Coldfusion Reference From Adobe](https://helpx.adobe.com/coldfusion/cfml-reference/topics.html)
2. [Open Source Documentation](http://cfdocs.org/)