Zend Framework

Filed in Lab Leave a comment

Anthony suggested that I try out the Zend Framework. It’s a pretty simple installation but I had a hard time findinga decent tutorial. The simple starter on the Zend site is set up to use SQL Lite and I just did not feel like installing and learning that at the same time. Then I stumbled upon this one that is quite good. Once you have completed it you will have a working CRUD for a single table. I found a couple of problems in the documentation vs. the example code though.

The tutorial shows how to set up your Apache virtual server for the project

ServerName zf-tutorial.localhost
DocumentRoot /var/www/html/zf-tutorial/public
AllowOverride All

This means that the server would serve files from the public directory. It then goes on to say to put the bootstrap (index.php) under the public directory. I was having some problems so I downloaded the example code to compare it with what I had done. I noticed that in the example code the index.php file was under the parent directory of public. This means the virtual host entry is wrong as it should point to zf-tutorial not public. I decided to leave the bootstrap file in the public directory as I did not want to have public access to the root of the application.

ini_set('display_errors', 1);
// directory setup and class loading
set_include_path('.' . PATH_SEPARATOR . '../library/'
. PATH_SEPARATOR . '../application/models'
. PATH_SEPARATOR . get_include_path());
include "Zend/Loader.php";
// load configuration
$config = new Zend_Config_Ini('../application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
// setup database
$db = Zend_Db::factory($config->db);
// setup controller
$frontController = Zend_Controller_Front::getInstance();
// run!