DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

EXT: My Extension

Author:Kasper Skårhøj
Created:2002-11-01T00:32:00
Changed:2009-02-19T21:58:11
Author:Author Name
Email:your@email.com
Info 3:
Info 4:

ZView

Extension Key: zview

Copyright, Zephir AG, Thomas Breuss, <thomas.breuss@zephir.ch>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from www.typo3.com

Table of Contents

ZView 1

Introduction 1

What does it do? 1

API Documentation 1

Controller Script 1

View Script 2

Options 2

View Helpers 3

Environment Helper 3

Image Helper 3

Link Helper 3

Mailto Helper 3

Page Helper 4

Popup Link Helper 4

Table Helper 4

Translate Helper 4

Url Helper 4

XmlEntities Helper 4

Writing Custom Helpers 4

Author 4

Introduction

What does it do?

ZView is a class for working with the "view" portion of the model- view-controller pattern. It exists to help keep the view script separate from the model and controller scripts. It provides a system of helpers and variable escaping.

ZView is something of an anti-templating engine in that it uses PHP natively for its templating.

Using ZView happens in two major steps:

Your controller script creates an instance of ZView and assigns variables to that instance.

The controller tells the ZView to render a particular view, thereby handing control over the view script, which generates the view output.

ZView extends Zend_View_Abstract. For more information about the Zend_View component refer to their online manual.

See http://framework.zend.com/manual/en/zend.view.html

API Documentation

For the API documentation have a look at “doc/api/” within the ZV iew extension folder.

Controller Script

The controller is where you instantiate and configure ZView. You then assign variables to the view, and tell the view to render output using a particular script.

See http://framework.zend.com/manual/en/zend.view.controllers.html

((generated))

Example

As a simple example, your controller has a list of book data that it wants to have rendered by a view. The controller script might look something like this:

<?php

$books = array(
 array(
 'author' => 'J. K. Rowling',
 'title' => 'Harry Potter and the Deathly Hallows'
 ),
 array(
 'author' => 'Khaled Hosseini',
 'title' => 'A Thousand Splendid Suns'
 ),
 array(
 'author' => 'Milton Friedman',
 'title' => 'Free to Choose'
 ),
    array(
        'author' => 'Jeffrey Toobin',
        'title' => 'The Nine: Inside the Secret World of the Supreme Court'
    ),
    array(
        'author' => 'J. R. R. Tolkien',
        'title' => 'The Children of Hurin'
    )
);
$view = t3lib_div::makeInstance('tx_zview');
$view->setPi($this);
$view->addScriptPath('/path_to_view_scripts/');
$view->books = $books;
$view->render('books.phtml');

View Script

Once your controller has assigned variables and called render(), ZView then includes the requested view script and executes it "inside" the scope of the ZView instance. Therefore, in your view scripts, references to $this actually point to the ZView instance itself.

See http://framework.zend.com/manual/en/zend.view.scripts.html

((generated))

Example

Now we need the associated view script called "books.phtml". A very basic view script could look like this:

<?php if (!defined ('TYPO3_MODE')) die ('Access denied.'); ?>

<h2>Example 1: Using a foreach</h2>
<?php if ($this->books): ?>
    <table border="1">
        <tr>
            <th>Title</th>
            <th>Author</th>
        </tr>
        <?php foreach ($this->books as $key => $val): ?>
        <tr>
            <td><?php echo $this->escape($val['title']) ?></td>
            <td><?php echo $this->escape($val['author']) ?></td>
        </tr>
        <?php endforeach; ?>
    </table>
<?php else: ?>
    <p>There are no books to display.</p>
<?php endif; ?>

Please note:

  • The first line is used to prevent direct calls to the view script.
  • In the example above we use the "escape()" method to apply output escaping to variables.

Options

Zview extends Zend_View_Abstract and has one additional option:

_pi: The base class for frontend plugins. May be set via setPi()

See http://framework.zend.com/manual/en/zend.view.html#zend.view.intr oduction.options

View Helpers

In view scripts, often it is necessary to perform certain complex functions over and over: e.g., formatting a date, generating form elements, or displaying action links. You can use helper classes to perform these behaviors for you.

See http://framework.zend.com/manual/en/zend.view.helpers.html

Since version 0.2 of this extension all helpers are prefixed with “t3”.

Examples:

  • $this->t3link()
  • $this->t3translate('Translate this')
  • $this->t3image('an-image.jpg', 200, 0)

Environment Helper

Returns System Environment Variables regardless of server OS, CGI/MODULE version etc. Basically this is SERVER variables for most of them. This is a wrapper for t3lib_div::getIndpEnv();

Example:
<?= $this->t3env('TYPO3_REQUEST_HOST') ?>
<?= $this->t3env('TYPO3_HOST_ONLY') ?>

For more examples refer to the inline documentation of t3lib_div::getIndpEnv().

Image Helper

Generates a cached image element using the image manipulation class of TYPO3.

Examples:
<?= $this->t3image('typo3conf/ext/zviewtest/pi1/res/colors.jpg', 200, 0, 'jpg') ?>
<?= $this->t3image('typo3conf/ext/zviewtest/pi1/res/colors.png', 150, 0, 'png') ?>
<?= $this->t3image('typo3conf/ext/zviewtest/pi1/res/colors.gif', 100, 0, 'gif') ?>

See example 7 of extension zviewtest.

Mailto Helper

Generates mailto link elements.

t3mailto()

Shortform of t3mailto()->link().

t3mailto()->href()

Generates a mailto href for use in attribute href of an a-tag.

See example 8 of extension zviewtest .

Page Helper

Retrieves a field of TYPO3s page table.

t3page(string $key)

Retrieve the field $key of the current page. Any fields of pages_language_overlay will be applied before the result is returned.

Table Helper

Generates a table element.

See example 6 of extension zviewtest .

Translate Helper

Translates a text string using the translation methods of TYPO3. If Zend_Translate is instantiated and registered in Zend Registry using key “Zend_Translate”, Zends translate adapter is used.

See example 4 of extension zviewtest .

Url Helper

Generates an url using the tslib_pibase methods of TYPO3.

See example 5 of extension zviewtest .

t3url()

Shortform of t3url()->thisPagePIvars().

t3url()->toPage()

Generates an URL to a certain page.

t3url()->toPagePIvars()

Generates an URL to a certain page using PI vars

t3url()->thisPage()

Generates an URL to the this page (the caller page).

t3url()->thisPagePIvars()

Generates an URL to the current page (the caller page) using PI vars.

XmlEntities Helper

Generates a XML conform text string.

Author

Thomas Breuss

Zephir Software Design AG

Tramstrasse 66

CH-4142 Münchenstein/Basel

http://www.zephir.ch

img-1 ZView - 4