2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Application Design Application design...
-
Upload
jasmine-alexander -
Category
Documents
-
view
213 -
download
1
Transcript of 2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Application Design Application design...
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Application Design
Application design – setting up
2010/11 : [2]Building Web Applications using MySQL and PHP (W1)Application Design
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
2010/11 : [3]Building Web Applications using MySQL and PHP (W1)Application Design
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
2010/11 : [4]Building Web Applications using MySQL and PHP (W1)Application Design
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.
2010/11 : [5]Building Web Applications using MySQL and PHP (W1)Application Design
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
2010/11 : [6]Building Web Applications using MySQL and PHP (W1)Application Design
Configuration/Settings
• Example of a basic configuration file:// database credentialsdefine('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 applicationdefine('APP_PATH','/home/username/public_www/w1');
// Set the timezone to avoid PHP warningsdate_default_timezone_set('Europe/London');
2010/11 : [7]Building Web Applications using MySQL and PHP (W1)Application Design
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
2010/11 : [8]Building Web Applications using MySQL and PHP (W1)Application Design
READ ME!
• Example of a readme.txt file:Super Cool PHP application--------------------------Author: Your name ([email protected])
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”
2010/11 : [9]Building Web Applications using MySQL and PHP (W1)Application Design
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
2010/11 : [10]Building Web Applications using MySQL and PHP (W1)Application Design
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: http://www.example.com/joe-bloggs/*/function printDirectoryContents(‘./datastore') {
// modified code}
2010/11 : [11]Building Web Applications using MySQL and PHP (W1)Application Design
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 directoryA 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…
2010/11 : [12]Building Web Applications using MySQL and PHP (W1)Application Design
Exercise
Hands On Exercise
Setting up your workspace