CNZ Framework Tutorial

Introduction

This framework is driven by configuration files and objects. Each task will be accomplished with a combination of instantiating an object and referencing configuration data for that object.

No particular directory structure is required, but, in the absence of some overriding consideration, the following directory structure is recommended.

$BASE --- app  Application code
       |
       |- cfg  Configurations
       |  |
       |  |- form    Form configurations
       |  |- table   Table configurations
       |
       |- dat  Data files
       |  |
       |  |- table  Table data
       |
       |- doc  Documentation
       |
       |- log  Log files
       |
       |- tmp  Temporary files
       |
       |- upload  Temporary upload directory
       |
       |- www  Web document root
          |
          |- image   Images (local to current directory)
          |- lib     Site library
          |  |- image   Images
          |  |- script  Client-side Scripts
          |  |- style   Style Sheets
          |
          |- script  Client-side Scripts (local to current directory)
          |- style   Style sheets (local to current directory)

      --- slib  Server library (Apache alias)
          |
          |- image   Images
          |  |
          |  |- brick   Link bricks
          |  |- button  Control buttons
          |
          |- script  Client-side Scripts
          |- style   Style sheets

Initialization

The foundation of the framework is the Cnz_Html class. This class performs several setup functions, including querying the browser for a preferred content type, selecting and sending appropriate HTTP headers. Just load the class and call init() as follows.

require_once 'Zend_Loader.php'; Zend_Loader::loadClass('Cnz_Html'); Cnz_Html::init(CONFIG_FILE);

Where CONFIG_FILE would be a configuration file containing something like the following. The commented lines show default settings.

[Html] domain = www.example.com sslDomain = www.example.com ;charSets = utf-8 ;languages = en-us ;transitional = no ;indent = \t wcagLevel = AAA ;brickDir = /slib/image/brick/ ;buttonDir = /slib/image/button/ ;logDir = log ;tmpDir = tmp ;uploadDir = upload ;logFile = html.log ;logLevel = info phpLogFile = php.log phpLogLevel = E_STRICT

At this point, you have everything up to and including the html start tag.

Database Connection

Cnz_Html::init() can also automatically configure and optionally establish a connection to a database. To prepare for a database connection, pass a second argument to Cnz_Html::init() that is the file containing the database configuration (it can be the same file). To automatically establish the connection, pass a third argument true.

If you do not automatically connect to the databae, you can do so later with the following.

Cnz_Html::dbConnect();

The database configuration looks like this.

[Database] type = pgsql host = localhost port = service_port dbname = database_name username = database_user password = database_password

The Header Block

After the initialization, the Cnz_Html_Head class can be used to effortlessly create a fully-populated header block.

$htmlHead = Cnz_Html::loadAndDisplay('Cnz_Html_Head');

The configuration data is as follows.

[htmlHead] ;author = <organization> ;copyright = "Copyright &copy; <organization>" description = Description for this Site ;distribution = global keywords = keyword list organization = Organization Name ;revisit = 7 days ;robots = index,follow scripts = mootools ;scriptAuto = yes ;scriptDirLocal = script/ ;scriptDirServer = /slib/script/ ;scriptDirSite = /lib/script/ styles = main:all,another:all ;styleAuto = yes ;styleDirLocal = style/ ;styleDirServer = /slib/style/ ;styleDirSite = /lib/script/ ;title = <domain>

You can also provide additional header information by simply placing it in a file named head.php in the current directory.

At this point, you manually perform your general page layout. Other framework classes will be used to easily create high-level objects within that layout, such as menus and tables.

Displayable Objects

The preceding objects were all one-of-a-kind (within a given page). All the displayable objects, however, are not necessarily unique. Therefore they can have custom configurations. And because they are displayable, they will also have associated style information, which may be custom. The framework automatically generates configuration names and style names for all displayable objects.

The configuration and style names are generated based on the type of object, which is defined as the third "field" in the class name. An optional name may also be specified when instantiating an object, which can be used to generate custom configuration or style names.

Configuration names are generated as

HtmlType[Name]

Style names are generated as

type[Subtype][-name][-suffix]

If an element has a custom style name, the default style name is also included in the class attribute. This allows default base styles to be defined and then overridden selectively. For example, a menu object named "main" would have the class set to "menu menu-main"

Documents

A document is just a div container with an associated style. It's purpose is to structurally identify the "real" data on the page, as opposed to the supporting structure like menus, banners, etc.

This class also serves to physically separate this real data for editing purposes. This allows the assignment of document editing rights separately from structural editing. This content is included from a separate file, defaulting to the file document.php in the current directory.

Menus

A menu is displayed as follows.

Cnz_Html::loadAndDisplay ( 'Cnz_Html_Menu', array ( 'name' => 'main', 'config' => true, 'style' => true ) );

Configuration data.

[HtmlMenu-main] list = " Home:/, About Us:/about/, Contact Us:/contact/, line1:, Careers:/career/, News:/news/, line2:, Client Login:/login/ "

Tables

See cfdemo.cnz.com for table and form examples.


[CNZ Framework][Valid HTML 4.01 Strict][Valid CSS2]