8. Setting up the virtualhost (Apache) <VirtualHost *:80> ServerName www.example.com ServerAlias example.com DocumentRoot /path/to/example.com/htdocs <Directory /path/to/example.com/htdocs> Options Indexes FollowSymlinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.php </Directory> SetEnv ENVPHP localhost ErrorLog /path/to/logs/example.com-error_log CustomLog /path/to/logs/example.com-access_log common </VirtualHost>
9. Directory structure app/ default/ <- the "default" application controllers/ <- here you define your controllers ErrorController.php IndexController.php models/ <- this is where your business logic is put views/ <- everything for presentations is put here helpers/ scripts/ index/ index.phtml error/ index.phtml library/ Zend/ <- this is the Zend Framework library htdocs/ <- this is where your bootstrap file is located images/ scripts/ styles/ .htaccess index.php
10. modify apache settings .htaccess RewriteEngine on RewriteRule !(js|ico|gif|jpg|png|css)$ index.php
11. bootstrap file index.php /** * Setup controller */ $controller = Zend_Controller_Front::getInstance(); $controller ->setControllerDirectory( '../application/default/controllers' ); $controller ->throwExceptions( false ); // should be turned on in development time // run! $controller ->dispatch(); require_once 'Zend/Controller/Front.php' ; <?php /** * My new Zend Framework project * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ set_include_path( '.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/default/models/' . PATH_SEPARATOR . get_include_path() );
12. view script index/index.phtml <?php /** * Default home page view * * @author Micehlangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ echo '<?xml version="1.0" encoding="UTF-8" ?>' ; ?> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns = "http://www.w3.org/1999/xhtml" > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" /> < title > New Zend Framework Project </ title > </ head > < body > Hello, world! </ body > </ html >
13. controller IndexController.php <?php /** * IndexController - The default controller class * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ require_once 'Zend/Controller/Action.php' ; class IndexController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { // TODO Auto-generated IndexController::indexAction() action } }
19. modifying IndexController.php <?php /** * IndexController - The default controller class * * @author Michelangelo van Dam (michelangelo@in2it.be) * @version $Id$ */ require_once 'Zend/Controller/Action.php' ; class IndexController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { $this ->headTitle( 'New Zend Framework Application' ); } }