Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


Views in Zend Framework are written in plain old PHP. View scripts are placed in application/views/scripts/, where they are further categorized using the controller names. In our case, we have an IndexController and an ErrorController, and thus we have corresponding index/ and error/ subdirectories within our view scripts directory. Within these subdirectories, you will then find and create view scripts that correspond to each controller action exposed; in the default case, we thus have the view scripts index/index.phtml and error/error.phtml.

View scripts may contain any markup you want, and use the <?php opening tag and ?> closing tag to insert PHP directives.

The following is what we install by default for the index/index.phtml view script:

<!-- application/views/scripts/index/index.phtml -->

        color: #0398CA;

        color: #91BE3F;

        color: #FFFFFF;
        background-image: url(;
        width:  600px;
        height: 400px;
        border: 2px solid #444444;
        overflow: hidden;
        text-align: center;

        background-image: url(;
        height: 100%;

<div id="welcome">
    <h1>Welcome to the <span id="zf-name">Zend Framework!</span><h1 />
    <h3>This is your project's main page<h3 />
    <div id="more-information">
            <img src="" />

            Helpful Links: <br />
            <a href="">Zend Framework Website</a> |
            <a href="">Zend Framework

The error/error.phtml view script is slightly more interesting as it uses some PHP conditionals:

<!-- application/views/scripts/error/error.phtml -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN";
<html xmlns="">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Zend Framework Default Application</title>
  <h1>An error occurred</h1>
  <h2><?php echo $this->message ?></h2>

  <?php if ('development' == $this->env): ?>

  <h3>Exception information:</h3>
      <b>Message:</b> <?php echo $this->exception->getMessage() ?>

  <h3>Stack trace:</h3>
  <pre><?php echo $this->exception->getTraceAsString() ?>

  <h3>Request Parameters:</h3>
  <pre><?php echo var_export($this->request->getParams(), 1?>
  <?php endif ?>


Zend Framework