Recommend Location to Set Some PHP Parameters (1 Viewer)

Steve R.

Retired
Local time
Today, 07:13
Joined
Jul 5, 2006
Messages
4,617
I am modifying the code to some of my (home LAN) web-pages in the hopes of streamlining and reducing unnecessary code. I am wonder what the industry standard practice is for locating code that will be used by subsequent web-pages. (Note: this project operates solely on a home LAN)

Below are the first few lines of the "homepage" (index.php). I just moved the line "require_once 'php_functions/functions.php';" into this block of code. So far, no errors have been experienced. So it is looking "good". Would it be appropriate to continue moving PHP code into this block?

Code:
<?php
// Start the session
session_start();
// Get current Working Directory			
$_SESSION['cwd'] = getcwd();
// This may work for all subsequent pages.  Need to verify.  
require_once 'php_functions/functions.php';	
?>
 

dan-cat

Registered User.
Local time
Today, 11:13
Joined
Jun 2, 2002
Messages
3,433
I do a fair bit of wordpress plugin development so I can show you how it's done in that CMS. Basically you create a class and include functions within that class to return what you need. You then instantiate that class by including the appropriate php file.

For example

Code:
class MyFirstClass {

    /**
    * Constructor.
    */
    function MyFirstClass() {

//Put whatever you code you need here when the class is created
}


function outputSomeHtml(){
     echo 'some html';
}

}

$myClass = new MyFirstClass();


Now in your web page include the file where the class resides...

Code:
require_once 'php_functions/myfirstclass.php';

and you can now use that class for what you will...

Code:
$myClass->outputSomeHtml();
 

Steve R.

Retired
Local time
Today, 07:13
Joined
Jul 5, 2006
Messages
4,617
:) Good one. I'm not yet up-to-speed on classes. I understand the concept and how it works. You have given me a new approach. However, I'm still near the bottom of the learning curve and trying to claw my way up. You have answered the question, now it is up to me to successfully apply. Thanks.
 

Users who are viewing this thread

Top Bottom