简体   繁体   中英

The best way to deploy one site for two companies in ColdFusion?

My client has multiple companies; different names/logos etc, but all the content on the sites are identical with the exception of said names/logos.

In a ColdFusion environment, what would be the best way for me to serve up identical content and swap out the logos/company names on the fly so I can keep everything in one spot? Is this a jQuery solution? regex? Or will ColdFusion enable me to deploy this in an efficient manner based on the url and session variables?

"Best" is a relative term. There are a large number of ways to do this.

I would probably use a switch on cgi.host_name in the onSessionStart() section of the application.cfc file. Store the correct site name, logo file, css reference, etc. in the session, and reference as needed. This, of course, presumes you are using sessions already.

If you want a more specific answer, you'll need to provide more information about what is already going on in your site.

I would recommend something similar to what @Ben Doom suggested; though not storing in session scope. Instead, I would recommend using Application scope. There's no reason to make every user's session repeat the same information over and over.

You can get 2 different "applications" (basically just different address spaces) running from the same codebase by giving them different application names. As Ben suggests, I would base the application name on a CGI variable. Using a hash will guarantee that the value will be safe to use as an application name, but won't be as easy to switch on.

Application.cfc:

component {
    this.name = hash(cgi.server_name);
}

Not all CGI variables are safe -- some can be modified by the user (referrer, ip, etc), so if you're going to use one of those, I recommend doing something like hashing it as I've done above to make sure it's safe to use here... But if you use one of the safe values (like cgi.server_name), then you should be safe using it without hashing/etc.

In that case, it would be much easier to setup the theme of the display to switch on which application is running:

Application.cfc:

component {
    this.name = cgi.server_name;
}

index.cfm:

<cfimport prefix="custom" taglib="#expandPath('./layouts')#" />
<custom:layout theme="#application.applicationname#">
    <!--- your content here --->
</custom:layout>

layouts/layout.cfm:

<cfparam name="attributes.theme" default="www.site1.com" />
<cfif attributes.theme eq "www.site1.com">
    <!--- include content for this theme --->
<cfelse>
    <!--- include content for this theme --->
</cfif>

(Tested on Win7/IIS7)

use ANT script to copy the correct logo and replace the correct name upon deploy?

or, make use of Coldbox environment detection support, and load up a different config file depending on the URL path?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM