Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Naming Components from the Application Root

Participant ,
Feb 16, 2009 Feb 16, 2009
My Coldfusion Web Root is: C:\ColdFusion8\wwwroot
My Application Root is: C:\ColdFusion8\wwwroot\mydomain.com

I have a component in my application called datasource and it is located at:
C:\ColdFusion8\wwwroot\mydomain.com\system\datasource.cfc

I want to be able to call this component based on my application root so that it can be referenced as "system.datasource". As that is the path to the component once I upload the site to my web host. Is it possible to do something to make this happen?

I have found that if I do the following in Application.cfc it makes it work, but I have a feeling this is not a recommended option:
<cfset this.customtagpaths = "C:\ColdFusion8\wwwroot\mydomain.com" />

Does that open me up to any problems or vulnerabilities?

The reason I do not want to use a mapping is that I am trying to make these components reusable for other applications as well, and if you use a mapping then the first part of the component name changes from app to app.

Any help or suggestions would be greatly appreciated. Thanks!
543
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 16, 2009 Feb 16, 2009
jeby,

You can accomplish this several ways but first, I wanted to note that I do not know of any specific vulnerabilities with adding the custom tag paths to an Application. There certainly could be and I'll leave that issue to anyone else that might have a more knowledgeable opinion.

One approach I could suggest is to create a Virtual Host on your development machine for each application on which you're working. That's probably not the right lingo for IIS but here's what I mean.

BTW - I'm guessing you're using IIS since your web and application roots show a Windows system but the same basic principles apply to Apache.

In IIS Admin, setup a new web site. Assign this site to a custom domain name, such as dev.mydomain.com and point the site to the application root directory you note in your original post.

Then, open the Windows Hosts file, which should be located in C:\Windows\System32\drivers\etc (Wiki link about Host file: http://en.wikipedia.org/wiki/Hosts_file). Edit the host file so that your custom domain name is there. Typically, this means adding a new line to the file with content similar to the following:
127.0.0.1 dev.mydomain.com

Anytime you point the browser on your local machine to http://dev.mydomain.com, the host file will intercept the request and make your local IIS serve the site.

As a result, the path system.datasource should begin its search from the top domain directory (your application root) and work down. This should work and mirror your production machine based on your description.

If you want to have these components available across many applications running on the same server, you can add them to a "dedicated" directory on the server and create a global mapping in the CF Administrator.

For example, I have a utilities folder on all my Windows servers. This folder contains all sorts of CFCs I reuse (getting US States and Canadian Provinces for a form select list, date/time functions, etc.) across many applications. I have a mapping in my CF Administrator(s) called ulitities, which points to the aforementioned directory. In all my applications, I instantiate a CFC from this directory as follows:
<cfscript>
myObj = createObject("component","utilities.StatesAndCountries.States");
</cfscript>

Hope this helps!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 16, 2009 Feb 16, 2009
Thanks Craig! I am currently using Windows, but I am using the Coldfusion Developers edition on port 8500 and no IIS... However, I am currently in the process of moving to Ubuntu and the Coldfusion runs on port 80 in apache on that. Do you have any insight as to doing this on apache as far as setting up the virtual sites and such? I think this idea may get what I need working....

Also... does anyone have any specific details on vulnerabilities or problems that may occur from adding the custom tag path? Because that seems to be working as well, and in theory should be platform independent.... just want to make sure I am not setting myself up for disaster.

Thanks again Craig!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 16, 2009 Feb 16, 2009
No problem, jeby! Ubuntu is pretty sweet and CF, in my tests, ran great on it (I use a Mac but have VMWare's Fusion in order to use both Linux and Windows Virtual Machines for testing).

On a 'nix system (Mac and Linux are the same here), you still need to setup the custom domain in the host file, which is, of course, located in another spot in 'nix:
Ubuntu should be in /etc/hosts
Mac has it in private/etc/hosts

Just as in the IIS example, open this file in a text editor of your choice and add the line as we had above.

Then, in Apache, you setup the Virtual Host in your httpd.conf file. Well, really, it should go in a httpd-vhosts.conf file. These files (httpd.conf and httpd-vhosts.conf) are typically located in the conf sub-directory of the Apache installation directory. On my Mac, it happens to be at /opt/local/apache2/conf but will vary from system to system and Apache install.

I'd use the terminal command: locate httpd-vhosts.conf

This will tell you where the files are. When you open httpd-vhosts.conf, you would add a VirtualHost tag to it:
<VirtualHost *:80>
ServerAdmin myemail@gmail.com
DirectoryIndex index.cfm index.html index.htm index.php
DocumentRoot /Users/Path/To/Sites/SiteName
ServerName dev.mydomain.com
</VirtualHost>

Lastly, be sure that your httpd.conf file includes the vhosts file. I think this is the default but might not be -- at worst, the include directive for the httpd-vhosts.conf file should be commented out so that you only have to uncomment it to have it working.

If this doesn't make sense, let me know and I can provide some better instructions 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 16, 2009 Feb 16, 2009
what i used to do when i had to develop on cf's built-in web server, was
to create an application variable depending on the server name:

<cfif cgi.server_name is "localhost">
<cfset application.cfcpath = "mysite.components">
<cfelse>
<cfset application.cfcpath = "components">
</cfif>

then when i need to invoke a component i would use
<cfinvoke component="#application.cfcpath#.componentname" ...>

mind you, this will probably NOT work if you have a . in your folder
name....

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 16, 2009 Feb 16, 2009
LATEST
I read somewhere where someone else had tried that but they said the problem is that you cannot use the variable name when extending components...

For example:
<cfcomponent name="myCFC" extends="#application.cfcpath#.components.masterCFC">
They said that this doesn't work.

Granted I don't extend to many CFC's, but I also am trying to avoid a practice that will cause problems if I get to a point I need to...

Did you ever run into that problem?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources