The Application Object
The Application object (technically Sodapop_Application) provides lots of handy
functionality for Sodapop applications. The class is implemented as a singleton, and a reference to it can
be obtained like this:
Initializing the Application
There are two ways of initializing the application, both of which take place in
The one-step process where the run()
method is called to both read the configuration files and process the request.
- The two-step process, where the initialize() method
is called (to read the configuration files) and the run()
method is called to process the request.
Most applications could safely use the one-step process. Occasionally, applications
will need to call some Application object methods that need to be accessed before
the request is processed, such as setTheme() or
addRoute(). In this case, they can use the two-step process
for the extra flexibility it provides.
- addRoute($route, $destination) (void)
- Adds a new route to the routing table. Must be called prior to run().
- clearCache() (void)
- If the APC cache is enabled, this method will clear it.
- connectToDatabase($connection_identifier, $driver_class, $hostname, $port, $user, $password, $database_name, $db_config = array()) (void)
- Creates a new database connection that uses the identifier named. The connection can later be accessed using getConnection($connection_identifier).
The framework will automatically connect to the database listed in sodapop.json.
- getConfig($key) (mixed)
- Returns a key from the application's sodapop.json file. If the key doesn't exist, null is returned.
- getConnection($connection_identifier = 'default') (Sodapop_Database_Abstract)
- Returns a the specified database connection. Calling with no argument will return the connection in sodapop.json.
- initialize() (void)
- Tells Sodapop to read the configuration files. Can be called explicitly in the application's /www/index.php, and should be placed before run() is called.
- run() (void)
- Tells Sodapop to process the request. Should be called in the application's /www/index.php. It will call initialize() if that method has not already been called.
- setDebug($boolean) (void)
- Turns debugging on or off. Can also be set through sodapop.json.
- setTheme($theme) (void)
- Sets the theme. This must be called before run() in /www/index.php to have any effect.