Databases Reference
In-Depth Information
iii. Next we create and instantiate a database connection.
Zend_Db_Adapter provides the database API abstraction layer, which
supports many SQL databases including DB2. You need to call
Zend_Db::factory() with the adapter name (DB2 in this case) and a list
of parameters with connection information. We now save this db
adapter $db in the Zend registry variable so that we can access it in our
application anywhere.
iv. Next we create an instance of Zend_View and set the path to the
instance to tell where to look for view template files. Zend_View is a
class for working with the "view" portion of the model-view-controller
pattern. That is, it exists to help keep the view script separate from the
model and controller scripts.
v. The last section of index.php creates the instance of the front controller
and specifies the directory where actual controller files are found. The
framework wants you to create controller classes in app/controllers
directory.
b. Now let us try to point your Web browser to the Web server with some
random path such as http://localhost:81/redbook/toc. In our case, you
should see an error. We expect the error and here is why. Since we
requested for redbook/toc, the framework looks for a controller called
RedbookController.php in the app/controllers directory. Since it did not
find any, it then looked for default IndexController.php. It did not find it
either. Remember, every request is treated as controller/action in the
framework. Index is the default for both the controller and the action. So
now, let us create IndexController.php as shown in Example 3-5 to get
going.
Example 3-5 IndexController.php
<?php
Zend::loadClass('Zend_Controller_Action');
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
echo 'what should I do?';
}
}
?>
There is another useful method called noRouteAction(). You can specify
a _redirect() call to redirect the requests for nonexistent pages to the
desired page. For example, as shown in Example 3-6 on page 104, if you
Search WWH ::




Custom Search