How to organize your application's basic information using the Stanford Web Application Toolkit

From Web Services Wiki

Revision as of 15:50, 16 December 2008 by Ddonahue (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search



You want to maintain consistency within your application by storing its name, URL, and base directory in a central location.


Use StanfordApp to organize your application-specific information.

Using a configuration file

Setting up a configuration file is one method of keeping track of your application's details. Create or edit a configuration file with the following fields.

  # Basic application info
  name: My Application
  admin email:
  admin name: Admin Name
  base url:
  base directory: /afs/

Simply pass the path to the configuration file to the constructor for StanfordApp to load the settings.

// Include StanfordApp
// Initialize and load settings
$app = new StanfordApp("/path/to/config.yaml");
// Test
echo "This application's name is " . $app->get_name();

Manual configuration

Alternatively, use the methods below to configure StanfordApp without a configuration file.

// Include StanfordApp
// Initialize StanfordApp object
$app = new StanfordApp();
// Set the name of the application
$app->set_name("My Application");
// Set the administrator's name and e-mail
$app->set_admin_name("Admin Name");
// Set the base URL
// Set the base directory

Retrieving your application's information

Use the functions below to retrieve your application's information.

// Name
echo $app->get_name();                     // My Application
// Administrator
echo $app->get_admin_name();               // Admin Name
echo $app->get_admin_email();              //
// Base URL
echo $app->get_base_url();                 //
// Base directory
echo $app->get_base_dir();                 // /afs/

Constructing absolute paths and URLs

StanfordApp provides the functions path and url to simplify the process of constructing absolute paths and URLs.

// Get the base URL
echo $app->url();                          //
// Append to the base URL
echo $app->url("about/index.php");         //
// Get the base directory
echo $app->path();                         // /afs/
// Append to the base directory to construct a path
echo $app->path("txt_files/my_file.txt");  // /afs/
Personal tools