Is it possible to share a CFC between applications? - coldfusion

I am running multiple applications (websites) that use common CFCs between them such as for string formatting and text parsing.
I am finding it difficult having to update the same functions across multiple sites and would like to just have one library of common CFCs that any ColdFusion application can take an instance of. It would be nice if the location of the CFC library could be anywhere (on the same server or maybe on a different server or in the cloud).
Looking at documentation I am not clear if this is possible and how to do it. If not what options do we have for code resuse across applications? Can anyone point me in the right direction please?

Pretend your CFCs are custom tags and use the documentation regarding custom tag locations. Here is one.
Here is some text from that link.
Storing custom tag pages
You must store custom tag pages in any one of the following:
The same directory as the calling page
The cfusion\CustomTags directory
A subdirectory of the cfusion\CustomTags directory
A directory that you specify in the ColdFusion Administrator
In other words, if you specify a location in the ColdFusion Administrator for Custom Tags, all Custom Tags and CFCs in that location will be available to all applications on the server.

To have a seperate folder, anywhere you want, to house common/shared CFCs all you need to do is create a mapping in your Application.cfc file and then use that to reference the CFCs and make instances of them.
In Application.cfc do the following:
<cfset this.mappings["/sharedcfc"] = "absolutepath\to\sharedfolder e.g. C:\Code\CFC" />
When you want to use a CFC in your application's code just do this:
<cfset MyCFCInstance = New sharedcfc.folder.nameofcfc() />
You can now have a common area for multi-purpose CFCs to use across your applications. What a life saver!

Related

Embedding a functional website inside a Squarespace webpage

First of all, thank you for everything that you do. Without this community, I would hate web design and be reliant on my teacher's outdated, static methods. Much love <3
So, this is a tricky one (maybe).
I want to have, essentially, an iframe on a webpage that contains a website I coded previously. It was a project for school that never went live, but I'd like to include it as part of my portfolio. Problem is, an iframe needs a URL for a source, but I just have the folder with more folders full of code, fonts, and images. How can I tell the browser to populate this box with everything from "name" folder? And then how will it know to run the code instead of just showing a file tree or something?
In the end, I want a page describing a previous web project and let the client experience that project within the one page. And I don't want to get a domain for every project I do.
Maybe there's an easier way I'm not thinking of?
To make it interesting, my new portfolio site is being made in Squarespace...maybe. I bought a domain from them because I had a promo code and wanted to try the platform, but I kind of hate it. I can't change any of the code and it won't maintain a connection to Typekit. So all I can do is change the basic appearance of preexisting elements. It's like WordPress all over again....LAME! Sadly, I already bought the domain.
Can Squarespace just be a host? Is there a way to download the raw code of these templates, edit it, and upload it again?
Thanks for all your help!
I want to have, essentially, an iframe on a webpage that contains a
website I coded previously.
Squarespace's file upload mechanism is very limited. Without using the Developers Platform, there is no effective way to upload many files at once. Furthermore, there is no way to create folders. Therefore, even if you were willing to upload each .html file and each asset one-by-one, there'd be no way to organize the files into folders (assuming that the "tree" you mentioned includes additional sub-folders).
Initially, in order to get the files to be accessible by Squarespace, you'd have to do one of the following:
Use Squarespace Developers Platform (A.K.A. "Developer Mode") and upload your to-be-iframed
(TBI) website files to the "assets" folder using SFTP or Git.
Host your TBI website files somewhere else (a different host
environment, for example) which will maintain your file/folder
structure.
How can I tell the browser to populate this box with everything from
"name" folder? And then how will it know to run the code instead of
just showing a file tree or something?
Assuming that the TBI website has an index.html file or home.html file or similar, and assuming you were to use the Squarespace Developer Platform, you'd insert the iframe either in a Code Block or within a template/.region file directly using something like
<iframe src="/assets/tbiwebsitefolder/index.html"></iframe>
while setting your other iframe attributes (such as height and width) as needed.
Is there a way to download the raw code of these templates, edit it,
and upload it again?
Yes. You select a template and then enable Developer Mode on that template. From there, you use SFTP or Git to download the template files, edit, and reupload.
You may benefit by reviewing some considerations of enabling Developer Mode on a Squarespace Template.
One other idea, to avoid the iframe and Developer Mode entirely, would be to capture images of the TBI website rendered in a browser, and then simply add those images to a gallery block or gallery page. This could allow you to convey the general idea of the project but would of course not capture the full "experience" of it.

How to structure a project directory in django?

Suppose you are building a Google website. (ok big dream)
Google has web search/youtube/email/news/etc ..
For this site, I'd like to structure my django directory like
Google/
search
youtube
email
news
and so on.
How do I structure such a site?
Create an app for each even though I'm not expecting to publish any of the category as an app?
Where would a common stuff (such as user model, utility modules, decorators..) would go, create a common_app?
Applications are reusable components for a django project that revolve around a central purpose. Applications don't need to map directly to your url structure of the website. While there is a standard structure for a django application to tie in with some of the management commands, such as tests.py, models.py, static files at /static/ you don't need to have any of it to be an application. For example, South is a popular django application used to provide database migrations. It adds a few management commands to manage.py.
When you are adding functionality and it doesn't map directly to the purpose of the application, just create a new one. So instead of thinking of it a a common_app, think about what the purpose of the application would be and how it might be utilized by your other applications.
In my projects, I tend to create a base application to handle the base template and static assets that are used in the base template. I'll create an accounts application to handle the user model and implement things like password reset. To deal with global notifications from any part of my site, I'll create an alerts application. The list can go on for a lot of the common functionality, but it's grouped in a way that revolves around a function and written as if it would be distributed.
So, in your specific case, you'll likely have at least an application for each of the domains such as search, youtube, email, and news, but also an application for each common component you might want to use across your core domains.

coldfusion application.cfm and affected files

If I have a site where there is a protected back end and I'm looking to use an application.cfm file, how can I tell which pages use the application filesa and which ones do not.
index.cfm
update/application.cfm
update/loginexpired.cfm
update/login.cfm
update/somesecurepage.cfm
update/someothersecurepage.cfm
I want updates/login.cfm to create the session if the login is correct.
If the secure pages update/somesecurepage.cfm and update/someothersecurepage.cfm are accessed without correct login the application should forward to update/loginexpired.cfm but I don't want any of the other pages to use application.cfm.
Is this plausible or should I use cfinclude instead?
Always make sure you name your Application.cfm and Application.cfc files with a capital "A". This way if you move from Windows to a case sensitive file system, you wont have an issue where ColdFusion cannot find your Application.cfm/cfc files.
As far as your question goes, with your current structure, all files in the "update" folder will use the Application.cfm file. It will be executed before any other code in those files. If you only want certain pages to redirect to a loginexpired page, then I would typically create a subfolder, put an Application.cfm file in that folder that includes the Application.cfm file from the parent folder: <cfinclude template="../Application.cfm" />. Then in this file, you would add your security check. in the parent Application.cfm file you would include the <cfapplication /> tag. If you are using sessions, be sure to enable session management in your cfapplication tag. (<cfapplication name="myappname" sessionmanagement="true" />)
You really should have an Application.cfm or Applciation.cfc file in the root of your site. If you do not, the application will run without an application scope. ColdFusion has a kind of "unnamed" application where this would run without a defined application name. You will most likely encounter undesired effects. All CF apps should have a named application, using the cfapplication tag or a Application.cfc file with this.name set.
If you are writing this as a new application, I would suggest you use Application.cfc instead of Application.cfm. You will have access to the application, session and request life cycles (onApplicationStart/End, onSessionStart/End, onRequestStart/End) as well as the onError and onMissingTemplate event handlers giving your more control over the flow of your application.
When a .cfm page is loaded, it will first look for an Application.cfc (The modern, recommended Application object) in the same folder and run it. If that file is not present, it will look for an Application.cfm (the old way of instantiating an Application.)
If neither exists in that folder, it will look up the tree to the next folder and check there for Application.cfc, then Application.cfm, it will repeat this until it finds one or gets to the root of the server.
Therefore, ALL of the files you listed in your 'update' folder will automatically use the application.cfm. Only the index.cfm listed in the root will not. (because neither Application.cfc nor Application.cfm are located in that folder.)
So it would be best to use an Application.cfc in the root of your site for everyone, and then put the locked down pages in a subfolder with a more restrictive Application.cfc.
I hope that answers your question directly. Otherwise, I agree with what Sean stated.
More info about Application.cfc and Application.cfm is available on Adobe's Coldfusion site.
I suggest to you to make a different Appliction.cfm (pref Application.cfc) for the public area and secure area. Also define a differnt name for those Application.
Oops, spelling error
I suggest to you to make a different Appliction.cfm (pref Application.cfc) for the public area and secure area. Also define a different name for those Application.

Coldfusion Application.cfc & Application.cfm in the same folder

I am modifying an existing web application which has been coded in Coldfusion. In the existing code, a large portion of the folders contain an Application.cfm file which sets the Application variables
However, part of my modification to these apps requires me to use the Application.cfc rather then the existing .cfm file.
Is there any potiential problems of having both of these files in the same directory? Or will Coldfusion default to using one over the other (or will it run both?)
Thanks,
Steven
EDIT
Just to shine some more light onto this. I am integrating a new centralized login system, but a caveat of this is that it must have a fall back login (in case of downtimne for login system). That is why i dont want to blow out the old code
If there is an Application.cfc file ColdFusion will use that. If you have both, Application.cfm will be ignored.

Why doesn't Railo read the 'customtag' path like CFMX 6.1 does?

I am trying to migrate from CFMX 6.1 to Railo 3.1.
I have custom tags in this directory for CFMX 6.1
C:\cfusionmx\customtags\myapp
I copied the directory to
{railo-web}/customtags/
and added this mapping through the Railo administrator and also enabled the "Search subdirectories" setting.
I get this error the moment I try to access a page that calls anything from this directory:
invalid component definition, can't find mycfc
My Railo installation is deployed through GlassFish v3.
I see the error the moment this script is loaded:
<cfscript>
mycfcinstance = createobject("component","mycfc");
</cfscript>
In the legacy app that I try to migrate, a lot of CFCs have been stored in CFMX 6.1's customtag path.
First of all, Railo simply does not support search for CFC's inside the Custom Tag directory. Seems that it will, one day.
Second, it looks like small misunderstanding the meaning of the Railo CFC-based custom tags, which you can manage using that "Archives & Resources > Custom Tags" page in Admin. You can find more about it in Railo's blog, for example in these posts: part one and two.
As for the Railo workaround for this legacy app, I couldn't find the way to imitate desired behaviour.
It can be inappropriate, but maybe you will end with batch-replacing
createobject("component","components.
with
createobject("component","
and creating mapping in the Application.cfc or Admin.
So, if you want to put cfc somewhere in the application root.
this.mappings["/components"] = getDirectoryFromPath(getCurrentTemplatePath()) & "components";
Yes, it's not really matches your problem, just an example.