Porting some PHP to ColdFusion
Ok, I'm working on converting some very basic PHP to port to dev server where client only has CF. I've never worked with it and I just need to know how to port a couple of things:
<?php
$pageTitle = 'The City That Works';
$mainCSSURL = 'header_url=../images/banner-home.jpg&second_color=484848&primary_color=333&link_color=09c&sidebar_color=f2f2f2';
require('includes/header-inc.php');
?>
I know:
<cfinclude template="includes/header-inc.cfm">
but how do I pass the var to include, and then how to use it in the subsequent included file?
Also in my CSS (main.php) I have (at the top):
<?php
header('Content-type: text/css');
foreach($_GET as $css_property => $css_value) {define(strtoupper($css_property),$css_value);}
?>
and im using constants like this:
#main-content a {color:#<?= LINK_COLOR ?>;}
How can I get this to work with CF as well?
I never thought that I would work with CF :)
a source to share
Coldfusion has several variable scopes that have different levels of visibility.
I'm not too familiar with PHP, but I'm assuming these variable declarations are available to any code in the request?
The equivalent of this is the request scope.
Any variables set in the scope of the request are available to any code while processing the request.
To set a variable in the query scope, simply do:
<cfset request.myVariable = myValue>
Or, in cfscript:
request.myVariable = myValue;
The other most commonly used area is the "variables" area. This is the default scope if you didn't specify a scope, so:
<cfset myVariable = myValue>
equivalent to
<cfset variables.myVariable = myValue>
The variable scope is visible to the code included in the CFInclude, so in your particular case you can use the variable scope or the query scope.
Here's a link to Areas in CF:
http://livedocs.adobe.com/coldfusion/8/htmldocs/Variables_30.html
a source to share
In CF, the $ _GET array becomes a url structure. You use cfloop to scroll it:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_j-l_16.html#2393950
<cfoutput>
<ul>
<cfloop collection = #url# item = "key">
<li>#key# = #url[key]#</li>
</cfloop>
</ul>
</cfoutput>
a source to share