Zend Framework Quick Start

Create a Rewrite Rule

Zend Framework's MVC implementation makes use of the Front Controller pattern. You must therefore rewrite all incoming requests (except those for static resources, which your application need not handle) to a single script that will initialize the FrontController and route the request.
If you're using mod_rewrite for the Apache web server, create the file QuickStart/public/.htaccess with the following contents:

# public/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

This set of rewrite rules specify that if the file exists under the document root directory, it should simply be served as a static resource. Otherwise, the request is for dynamic content and should be rewritten to our index.php script. Since all requests for non-static content will be rewritten to it, the index.php script serves as the entry point to our application.

Web Server Configuration & .htaccess Files

Some web servers may ignore .htaccess files unless otherwise configured. Make sure that your web server is configured to read the .htaccess file in your public directory.

Checkpoint

Let's make sure everything is working so far. Create the file index.php and add the following contents:

<?php echo 'Hello, Zend Framework!';

Now open your favorite browser and enter the URL http://localhost/ to see a simple page that says "Hello, Zend Framework!".

If this does not work, check your web server logs and make sure you have rewrite enabled with the correct rewrite rules for your web server.

Best Practices and Closing Tags

We didn't forget the closing (?>) PHP tag! We intentionally omit it to avoid unintentional output of whitespace in the response in certain cases. In fact, this is one of the best practices recommended in the Zend Framework coding standards.



Download & Install ZF
Create a Bootstrap File

Quickstart Downloads

Grab the QuickStart code for reference, or to start your project:

ZF Reference Guide - now in PDF!

The Zend Framework Reference Guide is now available in PDF format from Zend's high-speed content distribution network. Registration is required.

Documentation Archives

If you're looking for an older version of our reference guide, you'll find it in our download archives.