[line
197]
HTML class
This utility class provides general HTML support methods.
To use this class, load the class Cnz_Html and then call the static method init() prior to any output on the web page. The class is controlled by a configuration file.
Example INI (defaults shown as comments):
[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
brickDir is for link bricks such as the W3C validation bricks. buttonDir is for control buttons such as table next/prev.
indent defines the string used for a single level of HTML indentation.
tmpDir and logDir are relative to the application root directory, which is defined to be the parent of the web document root directory.
logLevel can be any of the log levels defined by Zend_Log (debug, info, notice, warn, err, crit, alert, or severe).
Example PHP:
Zend_Loader::loadClass('Cnz_Html');
The init() method will detect the capabilities of the client web browser and send the appropriate HTTP headers. XHTML 1.1 will be chosen as the content type if the browser prefers XHTML, else the content type will be set to HTML 4.01 Strict. If transitional is true, these will instead be XHTML 1.0 Transitional and HTML 4.01 Transitional, respectively.
init() also compares the list of languages in the configuration file to those in the Accept-Language header to find the best match. If there is no match, the language defaults to the first in the configuration list. The match can be retrieved using getLanguage().
init() processes the Accept-Charset header in the same way. Use getCharSet() to retrieve the selected character set.
Based on the detections above, the appropriate HTTP response headers are generated, and all prolog information up to and including the html start tag is output.
Given that the most common scenario for a database-driven site is to have a single database, init() has an option of connecting to that database. This connection is defined by passing a second argument to init() which is the name of the database configuration file. This is allowed to be in a separate file because it contains security information. The connection is a Zend_Db_Adapter.
A third boolean parameter specifies whether the connection will be made immediately, or postponed until it is accessed.
[Database]
type = pgsql
host = localhost
port = database_port
dbname = database_name
username = database_user
password = database_password
The valid database type values are: dblib, firebird, informix, mysql, oci, odbc, pgsql, sqlite. See PDO_* at http://www.php.net/manual/en/ref.pdo.php. Additionally, the non-PDO database types db2 and oracle may be used.
Leave the host undefined for socket connections.
Pages using this class must be written with XHTML syntax. If the end-tag shorthand sequence "/>" occurs anywhere else in the text, it must be replaced with "/>" or else the "/" (and any preceding whitespace) will be stripped when the page is served as HTML.
When using JavaScript, the value of the type attribute of the script tag should be set as follows.
type = "<?php echo Cnz_Html::getJavascriptType(); ?>"
There are also getter methods for several other settings.
The following directory structure is recommended. The recommended * BASE is /srv/www/host/.
$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