...

View Full Version : CFM - PHP question



n00ge
11-07-2006, 12:31 AM
I'm familiar with Coldfusion and am trying to get more into PHP. Is there an alternative to the Application.cfm in PHP or no?

Note: Application.cfm is a page that is automatically included at the beginning of each page request.

GJay
11-07-2006, 07:44 AM
if you're using apache as your web-server, then maybe take a look at http://www.zend.com/zend/spotlight/prepend.php

it gives you instructions on how to set up an auto_prepend, which will allow you to include a file of your choosing to all pages.

littlejones
11-07-2006, 08:04 AM
In other words, in PHP you can include any other file you want within your page. So, although I'm not fully familiar with the workings of Coldfusion, I would hazard a guess that Application.cfm includes information such as database connection details.

In PHP you would just create a separate file called whatever you want such as dbInfo.php or dbInfo.inc.php or dbInfo.inc, put all your database login credentials in it and then include it in all the pages where you want to connect to your database. You can refer to any number of databases on different servers in this manner.

In your code you would just put the following line.




includes("dbInfo.php");



I like to name mine .inc.php as it reminds me that those files are not standalone but are included within others. Many developers also like to have a folder named "Include" so they can put all their included files in there. The includes functionality allows you to cut your code into chunks by having different code for different jobs in separate files. It also means you can use that code again without having to search for it within all your other code.

GJay
11-07-2006, 08:25 AM
my limited understanding of CF, and the initial post, lead me to believe that the 'application' is included automatically, without having to explicitly declare it.
It's not exactly a lot of work to add one line to the top of each script, but if you're in control of apache, then adding a couple of lines in a single place is even simpler.

The other alternative is to setup the web-server to direct all requests to a single page ('Front Controller') which contains all the shared config info, and decides (based on the url that was requested, perhaps who the user is, whether they're logged in, etc.) what action should be taken.

Spookster
11-07-2006, 08:27 AM
In other words, in PHP you can include any other file you want within your page. So, although I'm not fully familiar with the workings of Coldfusion, I would hazard a guess that Application.cfm includes information such as database connection details.

In PHP you would just create a separate file called whatever you want such as dbInfo.php or dbInfo.inc.php or dbInfo.inc, put all your database login credentials in it and then include it in all the pages where you want to connect to your database. You can refer to any number of databases on different servers in this manner.

In your code you would just put the following line.




includes("dbInfo.php");

I like to name mine .inc.php as it reminds me that those files are not standalone but are included within others. Many developers also like to have a folder named "Include" so they can put all their included files in there. The includes functionality allows you to cut your code into chunks by having different code for different jobs in separate files. It also means you can use that code again without having to search for it within all your other code.

Application.cfm is automatically included in all pages of an application. That is not equivalent to your basic include file in PHP. What Gjay posted is an exact equivalent in PHP. The auto prepend feature of PHP allows you to automatically prepend every file with whatever file is specified in the auto_prepend setting. You do not need to use the include command.

n00ge
11-07-2006, 01:33 PM
Got it. Thanks for the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum