Databases Reference
In-Depth Information
Now, to understand the framework flow and make sure setup is working, let
us do this exercise:
a. Edit your index.php to look as shown in Example 3-4.
Example 3-4 index.php
<?php
include 'Zend.php';
function __autoload($class)
{
Zend::loadClass($class);
}
$dbuser = "db2admin";
$dbpass = "db2admin";
$dbname = "CONTACTS";
$params = array( 'username' => $dbuser,
'password' => $dbpass,
'dbname' => $dbname );
$conn = Zend_Db::factory('Db2', $params);
$db = new Database($conn);
Zend::register('db', $db);
$view = new Zend_View;
$view → setScriptPath('../app/views');
Zend::register('view', $view);
$controller = Zend_Controller_Front::getInstance()
→ setControllerDirectory('../app/controllers')
→ dispatch();
?>
Let us discuss the different parts here:
i.
First we include the zend.php .
ii.
Next, we are using PHP5's autoloader function to load the necessary
controller classes.
In PHP5 and above, you can define an autoloader function
( __autoload ) which is automatically called in case you are trying to use
a class which has not been defined yet. The scripting engine is given a
last chance to load the class with the __autoload function before PHP
fails with an error.
Search WWH ::




Custom Search