开发者

Porting some PHP to ColdFusion

开发者 https://www.devze.com 2022-12-28 01:05 出处:网络
OK, I\'m working with converting some very basic PHP to port to a dev server where the client only has CF. Ive never worked with it, and I just need to know how to port a couple things:开发者_如何学JA

OK, I'm working with converting some very basic PHP to port to a dev server where the client only has CF. Ive never worked with it, and I just need to know how to port a couple things:开发者_如何学JAVA

<?php
      $pageTitle = 'The City That Works';
      $mainCSSURL = 'header_url=../images/banner-home.jpg&amp;second_color=484848&amp;primary_color=333&amp;link_color=09c&amp;sidebar_color=f2f2f2';
      require('includes/header-inc.php');
?>

I know:

<cfinclude template="includes/header-inc.cfm">

but how to i get the var to be passed to the include and then how do I use it on 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 those constants like this:

#main-content a {color:#<?= LINK_COLOR ?>;}

How can I get that to work also with CF?

Never thought I'd be working with CF :)


Coldfusion has a number of variable scopes that have different levels of visibility.

I'm not too familiar with PHP, but I'm guessing those variable declarations are available to any code in the request?

The equivalent of this is the 'request' scope.

Any variables set in the request scope are available to any code in the processing of the request.

To set a variable in the request scope, you simply do:

<cfset request.myVariable = myValue>

Or, in cfscript:

request.myVariable = myValue;

The other most commonly used scope is the 'variables' scope. This is the default scope if you don't specify a scope, so:

<cfset myVariable = myValue>

is equivalent to

<cfset variables.myVariable = myValue>

The variables scope is visible to code included with CFInclude, so in your specific case, you could use the variables scope or the request scope.

Here's a reference to the Scopes in CF:

http://livedocs.adobe.com/coldfusion/8/htmldocs/Variables_30.html


In CF the $_GET array becomes the url struct. To loop through it you use cfloop:

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号