Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CFM - PHP question

    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.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:

    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.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by littlejones View Post
    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.

    PHP Code:

    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Got it. Thanks for the help.


  •  

    Posting Permissions

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