SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Invoking CF component without mapping

    Is it possible to invoke a component (sub directory components) from within another sub directory without mapping?

    Thank you in advance

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's an example of the folder structure you're trying to use?

  3. #3
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can invoke it if it's in the same folder as the file calling it but apart that it's done through mappings.

    Is there are reason you can't use mappings? It's normally a good idea to at least have one in your application pointing at the root of your project / application.

    What version of CF are you running? Mappings can be coded into your application directly from version 8.

  4. #4
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay! I have folder with components. Than I have two or three more folders with files that should be able to call the components. All folders are in in the root of the application!

    The reason that I can't ( can't is maybe a big word) use Mappings is that I don't have direct access to the CF administrator.

    I'm running CF8. How would I do such from Coldfusion?

    Thank you so much

  5. #5
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running CF8. How would I do such from Coldfusion?
    You want to have a look at this.mappings

    A good article on it here - http://samfarmer.instantspot.com/blo...e-Applications

    Yeah it's common, especially in shared hosting, for the Admin to be locked down. Pain in the **** but I guess that was one of the main reasons to introduce this.mappings.

    A few other articles on Google about it as well

    Cheers,
    James

  6. #6
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi James. Thank you for that. I'm going to ask you a really dump question though. I never used this before and even just migrated from Aplication.cfm to Application.cfc so this is all new to me. When I take the code in the example:
    Code CFM:
    <cfcomponent>
     
    <cfset this.mappings["/mymap"] = getDirectoryFromPath(getCurrentTemplatePath())>
     
    </cfcomponent>

    should /myMap be my components folder, i.e. /components? And if so can I than call the component from a template in subfolder like:
    Code CFM:
    <cfscript> 
        siteCFC      =  createObject("component", "components.cfcSite"); 
        getTypes     =  siteCFC.getTypes("#application.dsn#");
        getLocations =  siteCFC.getLocations("#application.dsn#");
        getFeatured  =  siteCFC.getFeatured("#application.dsn#");
    </cfscript>


    Thank you in advance.

  7. #7
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not a stupid question as you're right

    I mostly use "com" to reference my component but yeah by giving the mapping a reference name of "component" ColdFusion will look to use the directory path you've specified there to find your components.

    Only thing to keep in mind is this technique is application-specific. Mappings in the CFAdmin are global to every application running within ColdFusion, these ones will only work for files that are running within the same application - Hope that makes sense.

    BTW in your code example you don't need the application.dsn in quote marks or hashes. You're calling a variable so you can simply write it as this

    Code:
    getTypes = siteCFC.getTypes(application.dsn);
    Also, "food for thought". You could do this

    Code:
    siteCFC =  createObject("component", "components.cfcSite").init(application.dsn);
    
    site.getLocation();
    site.getFeatured();
    site.getTypes();
    Where init() is what they call a constructor (Google it ). You load the application.dsn value into the CFC on start up and it stores it internal. That way you don't need to reference it everytime you call one of its functions as the CFC can just use the value it was previously given.

    It's also worth thinking about just using the function calls when you need them rather than saving the results in a variable. More OOP

    Cheers,
    James

  8. #8
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi James,

    I'm still struggling to make this work. I did what you said (by the way a very good tip the
    Code CFM:
    .init(application.dsn)
    but I keep getting the error:

    Could not find the ColdFusion Component or Interface components.cfcSite

    The component cfcSite is in the folder components and I'm calling it from a template in a folder called shared. Both folders are in the root of this application.

    What I have in my Application.cfc so far is this:
    Code CFM:
    <cfcomponent>
     
    <cfset this.name="ANDRIANOPOYLOS">
    <cfset this.sessionManagement="true">
    <cfset this.clientManagement="true">
    <cfset this.setClientCookies="true">
    <cfset this.applicationTimeout=CreateTimeSpan(2,0,0,0)>
    <cfset this.sessionTimeout=CreateTimeSpan(0,0,20,0)>
    <cfset this.mappings["/components"] = getDirectoryFromPath(getCurrentTemplatePath())>
     
    <cffunction name="onApplicationStart" returnType="boolean" output="false">
    <cfset application.dsn = "Andrianopoylos">
     
    <cfreturn true>
    </cffunction>
    </cfcomponent>

    Like I said before I just migrated ( Or at least I try to ) to Application.cfc so that's why it still looks empty and maybe It's not even good what I'm doing. Can you please explain where I'm going wrong with this?

  9. #9
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's likely your getDirectoryFromPath(getCurrentTemplatePath()) for the mapping is wrong. That should be pointing at the components folder.

    Dump out that value and adjust it to match where that CFC folder is

  10. #10
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi James, sorry to bother you, hopefully for the last time, one more time I never had to use this kind of things. I used an example from Adobe and placed it in the components folder and this was the result:

    The current directory is: C:\inetpub\wwwroot\Andrianopoylos\components\

    So what do I have to change in
    Code CFM:
    <cfset this.mappings["components"] = getDirectoryFromPath(getCurrentTemplatePath())>

    Thank you in advance
    donboe

  11. #11
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No worries. All had to learn this stuff at some point

    In your Application.cfc do the following

    Code:
    <cfdump var="#getDirectoryFromPath(getCurrentTemplatePath())#" />
    What do you get?

    I'm guessing that'll give you the application's root directory path so what I think you'll need is something like this....

    Code:
    <cfset this.mappings["components"] = getDirectoryFromPath(getCurrentTemplatePath()) & "components" />
    Also worth dumping out ...

    Code:
    <cfdump var="#this#" />
    ... in your Application.cfc as that'll show you the current setup.

    Make sure to restart ColdFusion when you change anything. Mappings are saved in perm. memory for your application so the only way to change them is to overwrite then, delete them or restart ColdFusion.

    There are easier ways of doing that as well but one step at a time

  12. #12
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi James,

    This is driving me insane . I added one of the dumps just after the closing component tag
    Code CFM:
    <cfcomponent output="false">
    <cfset this.name="ANDRIANOPOYLOS">
    <cfset this.sessionManagement="true">
    <cfset this.clientManagement="true">
    <cfset this.setClientCookies="true">
    <cfset this.applicationTimeout=CreateTimeSpan(2,0,0,0)>
    <cfset this.sessionTimeout=CreateTimeSpan(0,0,20,0)>
    <cfset this.mappings["components"] = getDirectoryFromPath(getCurrentTemplatePath()) & "components" />
    </cfcomponent>
    <cfdump var="#this#" />
    and this is what I get for all the hard work :

    Invalid CFML construct found on line 17 at column 1.
    ColdFusion was looking at the following text:
    <


    What am I doing wrong?

  13. #13
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No that won't work....

    What does this give you?

    Code:
    <cfcomponent>
     
    <cfset this.name="ANDRIANOPOYLOS">
    <cfset this.sessionManagement="true">
    <cfset this.clientManagement="true">
    <cfset this.setClientCookies="true">
    <cfset this.applicationTimeout=CreateTimeSpan(2,0,0,0)>
    <cfset this.sessionTimeout=CreateTimeSpan(0,0,20,0)>
    <cfset this.mappings["/components"] = getDirectoryFromPath(getCurrentTemplatePath())>
     
    <cffunction name="onApplicationStart" returnType="boolean" output="false">
    <cfset application.dsn = "Andrianopoylos">
     
    <cfreturn true>
    </cffunction>
    
    <cffunction name="onRequestStart" returnType="any" output=true>
    <cfdump var="#this.mappings#" />
    <cfabort/>
    <cfreturn />
    </cffunction>
    </cfcomponent>
    Also have a look at this, a template for Application.cfc, as it'll help you get your head around Application.cfc a bit more....

    http://www.coldfusionjedi.com/downlo...cation.cfc.txt

  14. #14
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi James,

    Forget this part

    It gave me an error stating:

    Invalid request of Application.cfm, Application.cfc, or OnRequestEnd.cfm file.

    so i gave it temporary a differnt name and this is what the struct gave me:




    I saw what was happening when I opened any other page it gave me
    Code CFM:
    /components   C:\inetpub\wwwroot\Andrianopoylos\

    So do I understand it right then that, as you earlier suggested, the mappings should be:
    Code CFM:
    <cfset this.mappings["components"] = getDirectoryFromPath(getCurrentTemplatePath()) & "/components" />

    Thank you again

  15. #15
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Little update on this! I think I'm near to the solution because the pages from the shared folder are opening but I get error messages like:

    Variable PROPERTY_LOCATION_NAME is undefined.

    This is a value I have in a dropdown list. The strange thing is though that I don't get an error on PROPERTY_LOCATION_ID, which is the value in the same dropdown list. Any ideas?

  16. #16
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got the mapping stuff sorted.

    Probably need to see some code for your new issues . I'd also suggest starting a new thread for it. Just easier for people to pick it up from the main listing.

    Cheers,
    James

  17. #17
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi James. It is sorted completely. I guess I was so tired after trying and trying that I didn't see some obvious errors. Thank you for you time and patience.

    cheers,
    Donald

  18. #18
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On a side note, you can also use cfimport to create a namespace of a folder containing custom tags. It works like so:

    Code CFM:
    <!--- create the namespace --->
    <cfimport taglib="/path/to/your/directory" prefix="myTags">
     
    <!--- use the tags --->
    <myTags:tagOne attribute1="some value"  attribute2="another value">
     
    <myTags:tagTwo>
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  19. #19
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,068
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by creole View Post
    On a side note, you can also use cfimport to create a namespace of a folder containing custom tags. It works like so:

    Code CFM:
    <!--- create the namespace --->
    <cfimport taglib="/path/to/your/directory" prefix="myTags">
     
    <!--- use the tags --->
    <myTags:tagOne attribute1="some value"  attribute2="another value">
     
    <myTags:tagTwo>
    Thank you for that, very useful


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •