Skip to content
jlesueur edited this page Apr 3, 2012 · 3 revisions

Using Zones

Before reading this tutorial you may want to familiarize yourself with these pages: MVC and AppInstanceLayout.

Overview

In the MVC paradigm Zones are the controller. They take care of initializing and executing requests from the browser. The general approach is on page views to get some information from your domain logic and pass it into the views. Then when a form is posted, save the form data, and redirect the user to the next page.

Paradigm

In zinc, Zones are like folders in a file system. They may contain any number of page functions, which are like files inside a folder. Zones are logical containers for pages that are related. For example, ZoneUser may have pages for user creation, modification, deletion and listing.

Routing

Zones are automatically mapped to urls. index.php/myzone maps to ZoneMyZone::pageDefault($p, $z). Pages are also automatically mapped: index.php/myzone/mypage maps to ZoneMyZone::pageMyPage($p, $z). ZoneDefault is called when no matching zone can be found.

POST

Zones may define postMyPage($p, $z) as well to handle POST requests separately from GET. A common design pattern is to declare a pageMyPage($p, $z), and in the view include a form which posts to the same url that requested the page. Then the developer creates a postMyPage($p, $z) which saves the form, and redirects the browser to a new page.

Initializing

Developers can override the Zone::initZone($p, $z) function to handle logic that is common to all pages in the zone, such as permissions checking and common variable assignments.

Parameters

Zones may declare required parameters by overriding getParamNames() to return an array of one or more parameters.

public function getParamNames()  
{  
    return array('paramOne');  
}  

public function pageMyPage($p, $z)
{
    var_dump($z);
}

This will now accept the url index.php/myzone/:paramOne/mypage at ZoneMyZone::pageMyPage($p, $z) and $z will be array('paramOne' => ':paramOne').

Any path elements after the page are passed as page parameters. index.php/myzone/:paramOne/mypage/param1/param2 calls ZoneMyZone::pageMyPage($p, $z) with $p = array('param1','param2')

Clone this wiki locally