Presentation is loading. Please wait.

Presentation is loading. Please wait.

Application design – setting up

Similar presentations


Presentation on theme: "Application design – setting up"— Presentation transcript:

1 Application design – setting up

2 Get Organised! When building web applications, you usually end up with a lot of files! It is essential that you develop a system to organise these files that you are comfortable with and stick to it! Every task/project you build should have its own directory

3 Get Organised! An example directory structure for your workspace:
All projects stored in one directory New directory for each project Directory to store common files

4 Include files A web application WILL utilise include files
Not only PHP files but also XHTML snippets (header, footer etc) Advisable to store these files in their own directory within your project.

5 Configuration/Settings
Web applications usually have some settings that need to be changed depending on the environment they are running in. eg: database credentials, file paths etc If we store all of this data in one file which we then include in our scripts, our application becomes much more portable

6 Configuration/Settings
Example of a basic configuration file: // database credentials define('DB_HOST', 'mysqlsrv.dcs.bbk.ac.uk'); define('DB_NAME', 'my_dbname'); define('DB_USER', 'my_username'); define('DB_PASSWD', 'my_password'); // The path to the application define('APP_PATH','/home/username/public_www/w1'); // Set the timezone to avoid PHP warnings date_default_timezone_set('Europe/London');

7 READ ME! As a developer, you won’t always be responsible for deploying the application. Provide all the information that is required to get the application up and running. Databases that need to be created Directory permissions that need to be set. Location of the application configuration file! Do this in a plain text file saved as readme.txt in the application root directory

8 READ ME! Example of a readme.txt file: Super Cool PHP application
Author: Your name Before deploying… 1. make sure the “data” directory is writable. 2. Change values defined in “includes/config.php” to match current environment. 3. “users” database will be created by PHP if it does not exist. Or you can create it manually using the sql found in “includes/database_setup.sql”

9 Credit where credit is due!
There are endless PHP scripts and applications freely available to download and use. You are encouraged to explore, modify and utilise these resources. BUT, You must always give credit to the original author Use comments in your source code Add a note to your readme.txt

10 Credit where credit is due!
Giving credit for ‘borrowed’ code: /* Function to print a list of files in a specified directory. This function is based on code found on Joe Blogg’s website. It has been modified by me to produce valid XHTML. Ref: */ function printDirectoryContents(‘./datastore') { // modified code }

11 Abstraction Our goal when writing PHP applications, is to create as much re-usable code as we can. We do this by breaking the application into micro tasks. One function that prints an XHTML list of the files stored in a directory A group of functions that each perform one of the tasks necessary to achieve our end result One function to retrieve a directory’s contents as an array One function to print an array as an XHTML list etc… 8 4

12 Setting up your workspace
Exercise Hands On Exercise Setting up your workspace


Download ppt "Application design – setting up"

Similar presentations


Ads by Google