Acession Common Components in ColdFusion

Hi,
My site is expanding and I am now creating directories from the root to segregate different products.

I have CFINLUDE header and footers that refer to images  (in an Image directory from the root) and root programs if the user is not loged in).

I am having an issue using these CFINCLUDE headers and footers in new directories as the CFINCLUDES templates have HTML that refer to src="image/myimage.jpg" (for example).  

These work fine in www.mydomain.com/myprogram.cfm.  But they don't resolve as I'd like in www.mydomain.com/product1/myprogram.cfm as the relative reference doesn't resolve.

Do I have to use absolute references?  This makes test versus production tricky?

Please advise.

Thanks in advance,
hefterr  
LVL 1
hefterrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

azadisaryevCommented:
you can use paths relative to website root (start path with /):

src="/images/myimage.jpg"

Azadi
hefterrAuthor Commented:
Hi azadisaryev,
Thanks for help.  But It didn't seem to work?  I took a root reference :

<td align="right" class="homelinks"><img src="images/CP_SecureLinks.jpg" alt="Home - Navigation" width="197" height="16" border="0" usemap="#Map2" /></td>

and changed it to :
<td align="right" class="homelinks"><img src="/images/CP_SecureLinks.jpg" alt="Home - Navigation" width="197" height="16" border="0" usemap="#Map2" /></td>

But the image was not found (testing locally)?  Not sure how to debug this either (what path is the browser looking for)?

Please advise.
hefterr
_agx_Commented:
> Not sure how to debug this

You can use the ExpandPath() function to see the physical image path the server is looking for

<cfoutput>
    Debug  #ExpandPath("/images/CP_SecureLinks.jpg")#
</cfoutput>

It all depends on _your_ site root, but on one of my local pc's,  my web site root "/" is:
      c:\ColdFusion8\wwwroot

So _my_ server would be looking for this image here:
     c:\ColdFusion8\wwwroot\images\CP_SecureLinks.jpg

IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

hefterrAuthor Commented:
Hi aqx,
I doing something wrong as it works in production but not locally:

Prod : Debug C:\ColdFusion8\wwwroot\centrispoint\images\CP_SecureLinks.jpg    <==OK

test  with Slash: Debug C:\ColdFusion8\wwwroot\images\CP_SecureLinks.jpg <==== WRONG PATH

test without slash : Debug C:\ColdFusion8\wwwroot\centrispoint\images\CP_SecureLinks.jpg <==GOOD

I am using Dreamweaver to define my site locally when I test as :C:\ColdFusion8\wwwroot\centrispoint and I have physically defined :
c:\ColdFusion8\wwwroot\centrispoint as my directory site both on test and production.

I'm not sure what's going on locally.

Heeellllp!
hefterr
hefterrAuthor Commented:
Another piece of information,
Locally I ran the template : http://localhost:8500/centrispoint/test_root.cfm   -  to test both cases.  But when I add the slash in front of the image reference, the debug gives me:

Debug C:\ColdFusion8\wwwroot\images\CP_SecureLinks.jpg  ???

I'm not sure what is going on.  I am using the CF application server locally and IIS on our server.

Thanks in advance,
hefterr
hefterrAuthor Commented:
Sorry, one more piece of info.  You can look at http://www.centrispoint.com/test_root.cfm  on my server which is your test code.

hefterr

hefterrAuthor Commented:
OK - I get it now.  I just don't know what to do about it to be insynch locally and on our server with the same code.

The CF application server on has 1 root : c:\ColdFusion8\wwwroot. When I test, I always add the subfolder : http://localhost:8500/centrispoint/

But on our server, I define the root as c:\ColdFusion8\wwwroot\centrispoint.

So my code with the slash will work fine on the server but not locally as the "root" is technically different.

I have a headache!
hefterr
_agx_Commented:
Right.  But if you change the root of your local server to match, you'll get the same results.  

http://www.adobe.com/support/coldfusion/adv_development/config_builtin_webserver/config_builtin_webserver04.html
azadisaryevCommented:
>> But if you change the root of your local server to match, you'll get the same results.

yes, but that would break any other 'sites' you might have under built-in server's webroot.

Azadi
_agx_Commented:
> yes, but that would break any other 'sites' you might have under built-in server's webroot.

True, but I'm not sure what the alternatives are when using the built in server rather than IIS, Apache, etc..
azadisaryevCommented:
i am testing an alternative that does not involve switching web servers right now :)

Azadi
_agx_Commented:
> True, but I'm not sure what the alternatives are

   ... other than just using setting the path as variable in your Application.cfc, and changing it before moving
   to the the prod site

   ie   application.baseImagePath = "/whatever/"

   Then in the cfinclude use
   <img src="/#application.baseImagePath#/CP_SecureLinks.jpg" ...>
   

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_agx_Commented:
> i am testing an alternative

   Cool. Let us know, because I could use something like that on one of my machines :)
hefterrAuthor Commented:
You are both correct.  I'd have to flip/flop my root locally to test different site/applications.

The other solution, is to change the root on the server (IIS) to C:\ColdFusion8\wwwroot and have a stub program for each site CFLOCATION to the appropriate application directory.

Not sure if that's a good idea security wise (or is that how is supposed to be done?).  I have 3 site/applications on the same server with separate directories for each under  C:\ColdFusion8\wwwroot \sitename.

What does everyone else do?

Thanks again,
hefterr
azadisaryevCommented:
ok, here is what you can do with built-in web server:

instead of adding/changing a virtual mapping for web root like the article _agx_ linked to describes, just add a new virtual mapping:

<virtual-mapping>
    <resource-path>/centrispoint_images/*</resource-path>
    <system-path>C:/ColdFusion8/wwwroot/centrispoint/images</system-path>
</virtual-mapping>

the mapping name (resource-path) should be site-specific - DO NOT name it just /images, as every other 'site' you have under the webroot will then redirect all requests to /images to centrispoint/images folder!

now change your img tag to <img src="/centrispoint_images/CP_SecureLinks.jpg" />

voila! the image is displayed in pages in 'root' and in sub-folders now.

now, on your prod server you will need to create a virtual dir /centrispoint_images and point it to the location of /images folder.

Azadi
hefterrAuthor Commented:
Guys,
Let me know if you think of anything else.  I like aqx's idea of using the application.cfc to control the difference between test and production for shared components at different levels.

Still curious what experienced CF web developers do with multiple sites on their local PCs?

Thanks again to both for your expertise!!!
_agx_Commented:
> voila! the image is displayed in pages in 'root' and in sub-folders now.

But it seems like that would require a different mapping on PROD for every site?  I'd rather change dev, than prod.
hefterrAuthor Commented:
azadisaryev,
I'm a bit new here so I don't know what you mean by :
>add a new virtual mapping:

<virtual-mapping>
    <resource-path>/centrispoint_images/*</resource-path>
    <system-path>C:/ColdFusion8/wwwroot/centrispoint/images</system-path>
</virtual-mapping>

FYI.  I work at home and my PC is running MS VISTA Home Premium.

hefterr
azadisaryevCommented:
>> But it seems like that would require a different mapping on PROD for every site?  I'd rather change dev, than prod.

yes, it would require a virtual dir set up on the webserver on prod server (i.e. an IIS virtual dir). no changes to cf server are required on prod server.

but afaik, this is the only way to go about it if your local dev is on built-in cf webserver (JWS).

>> Still curious what experienced CF web developers do with multiple sites on their local PCs?

i am pretty sure 'experienced CF web developers' run a proper web server (like Apache) in their dev environment. at least i do :)

Azadi
azadisaryevCommented:
>> I'm a bit new here so I don't know what you mean by :

read the article _agx_ posted a link to:
http://www.adobe.com/support/coldfusion/adv_development/config_builtin_webserver/config_builtin_webserver04.html

or this one:
http://livedocs.adobe.com/coldfusion/8/htmldocs/webservmgmt_3.html#102393

you need to add the virtual mapping in {cf_root}/wwwroot/WEB-INF/jrun-web.xml file.

Azadi
_agx_Commented:
> yes, it would require a virtual dir set up on the webserver on prod server (i.e. an IIS virtual dir)

That's what I mean. When it comes to changes, I'd prefer to modify dev to make it match prod, rather than touching prod in any way.  (Though I don't like the variable idea much better... I have done it though).  Besides, as you say - the best solution is to use a real web server anyway ;-)
hefterrAuthor Commented:
azadisaryev,
Still not sure what you mean by :
>add a new virtual mapping:
<virtual-mapping>
    <resource-path>/centrispoint_images/*</resource-path>
    <system-path>C:/ColdFusion8/wwwroot/centrispoint/images</system-path>
</virtual-mapping>

Remeber, the problem I have is locally, as the server side is fine.

hefterr
_agx_Commented:
If you don't want to make any changes to the prod server, I believe you only have two choices:

1) Use a variable in your application.cfc  - OR
2) Change the web root of your local server to match the one on prod.  

To change the web root for the built in server the full instructions are here:
http://www.adobe.com/support/coldfusion/adv_development/config_builtin_webserver/config_builtin_webserver04.html

Summary:  
- Find the jrun-web.xml file.  Make a backup copy.  
- Change the root to match the one on prod ie C:/ColdFusion8/wwwroot/centrispoint.
- Save the file and restart CF

<virtual-mapping>
    <resource-path>/*</resource-path>
    <system-path>C:/ColdFusion8/wwwroot/centrispoint/</system-path>
</virtual-mapping>




azadisaryevCommented:
just remember that if you change your built-in cf server's web root as _agx_ suggest, any other sites* you have on your local server will stop working (unless you move them all into C:/ColdFusion8/wwwroot/centrispoint/ folder).

* - by 'sites' i mean if you have several websites each in separate subfolder on your local server in C:/ColdFusion8/wwwroot.

Azadi
hefterrAuthor Commented:
OK Thanks guys.

I think I'll initially go the application.cfc route as I'd have to flip flop the local root when developing/testing the other application/sites.

Perhaps I should ultimately install IIS locally (and upgrade to Window 7) to be in synch with the Windows 2003/IIS server.

Thanks again for your time an effort on this question (it was an interesting one :)!

hefterr
_agx_Commented:
> Perhaps I should ultimately install IIS locally

Either that or Apache, etc... The built in web server is very limited.  So to do what you need ... you need a "proper" web server as Azadi says :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.