Display Components in Railo

I would like to put all my CFCs in the / components folder and be able to name them from different places in the application, for example. from / forums / index.cfm.

How do I configure the mapping settings?

+6
source share
2 answers

Summary...

There are several ways to configure the mapping, and indeed, two different display types:

  • Traditional mapping is created using the administrator and can be used anywhere in your CFML code. Railo supports mappings for each context and each server of this type.

  • There is also a mapping for each application, created either in your Application.cfc application or through the cfapplication tag, which can be used in most places, but is a run-time construct, so it cannot be used at compile time.

Also, if you have global components, you can avoid the use of matching and just tell Railo where your components are so that you can access them directly.

Create a mapping for each context:

Go to the Railo administrator (i.e.Http http://domain/railo-context/admin/web.cfm ), and in the menu a little over half the way you will find "Archives and Resources", in which there is "Mappings".

In the "Virtual" column, enter /components and in the "Resource" column, enter the absolute path to this directory (for example, / home / user / public_html / components), then click the "Save" button.

You can also programmatically create a context mapping using the cfadmin tag with the "updateMapping" action.

(Everything here also applies to mappings between servers, with the exception of using Admin Admin, not the web administrator. The mappings on the server are visible, but read-only in the web admin interface.)

Create a mapping for each application:

To create a mapping only for a specific application, you can do this in Application.cfc

Just create a variable called this.mappings that contains the structure of your virtual and resource values, for example:

 This.Mappings = { '/components' : '/home/user/public_html/components' } 

This mapping will only apply to this application, allowing you to have the same display point in different places for different applications.

Railo also allows you to create mappings between applications inside Application.cfm using the cfapplication tag - for example:

 <cfset MappingStruct = { '/components' : '/home/user/public_html/components' } /> <cfapplication mappings=#MappingStruct# /> 

Note. app-level mappings have some limitations because they exist at run time, but not at compile time (therefore, for example, they cannot be used for custom tag libraries where the taglib attribute is evaluated when compiling the template).

Link to component with display:

Any of them will allow you to do:

 MyObj = createObject('component','components.NameOfFile').init() 

Or:

 MyObj = new components.NameOfFile() 

(Note that you are not using /component/nameoffile , as you could when using mapping.)

Global components without display:

If you want to access components all over the world without matching, go to the "Components" section (just below "Mapping in the menu") and enter your path of absolute components in the "Additional resources" section. (Disable Trusted without warning.)

Then you can simply create your objects without displaying components. :

 MyObj = new NameOfFile() 
+9
source

You must define your mappings in Application.cfc . Check out these related questions.

railo application.cfc this.mappings does not work

How to enable mappings in Application.cfc from an external properties file?

+3
source

Source: https://habr.com/ru/post/923476/


All Articles