Home > Lab > Zend Framework

Zend Framework

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.

<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');
 
include('../helpers/print_var.php');
include('../helpers/MyIterator.php');
 
 
// directory setup and class loading
set_include_path('.' . PATH_SEPARATOR . '../library/'
. PATH_SEPARATOR . '../application/models'
. PATH_SEPARATOR . get_include_path());
 
include "Zend/Loader.php";
Zend_Loader::registerAutoload();
 
// 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);
Zend_Db_Table::setDefaultAdapter($db);
 
// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('../application/controllers');
 
Zend_Layout::startMvc(array('layoutPath'=>'../application/layouts'));
 
// run!
$frontController->dispatch();

Leave a Reply

Trackbacks:0

Listed below are links to weblogs that reference
Zend Framework from rhythmicalmedia.com
TOP