☸ Introduction to CCViews ☸

CCViews is a parameterizable nested view loader with an optional global-scope function API.

How to use CCViews

Put ccViews.php and (optionally) ccViewsGSFAPI.php somewhere accessible to your PHP-enabled webserver, create a folder called 'views' in the same directory, and —if you want to use the global-scope function API— include the following 2 lines in the PHP file that will act as a holder (see below for more about holders):

require_once 'path/to/ccViewsGSFAPI.php'; //fs path; abs or rel to holder

To create a CCViews object directly, and not use ccViewsGSFAPI.php, you can use the static factory method CCViews::create(): require_once 'path/to/ccViews.php'; //fs path; abs or rel to holder

Replace 'path/to/' with the actual filesystem path. That's it! createViewsObject() creates a single global CCViews object (to use with the global-scope API), and both it and CCViews::create() can take 3 optional parameters (in order):

  • a default associative array of GET parameters to use when there are no 'get' or 'post' data;
  • an integer specifying the maximum view depth;
  • a view-file extension to use instead of the default (should probably start with '.').

Some characteristics of views (for everyone)

  • must be in a folder called 'views', a sibling of the ccViews.php file;
  • must have the view-file extension (currently '.thtml');
  • must be valid PHP, which, since PHP is a superset of HTML, can mean pure HTML;
  • should expect all relative web and filesystem paths, including those of PHP includes, to be relative to the 'holder'.
  • should contain an HTML comment or a PHP block comment listing its dependencies, if any. The comment should have the following form. /* depends: css/someCSSFile.css, js/someJSFile.js, etc. */

Some characteristics of views (for programmers)

  • can load sub-views by calling the API functions viewByIndex() or viewByName();
  • are loaded by a CCViews method, so--
    • in the top-level scope of a view, '$this' is the CCViews object;
    • globals need to be set using the helper functions setGlobal(), setGlobals(), or after using the 'global' keyword, not just by assignment in the top-level scope of a view (PHP function definitions in a view, however, will have global scope).

The URL syntax

Since the views can be nested, and can be specified in the URL's query string, understanding the URL syntax is important if you want to use viewByIndex().

The URL syntax is as follows.



holder.php is the file that holds the views (the 'holder', e.g. this page);

all parameters are optional;

dx, means 'depth' x (the depth of the groups, starting at depth 0);

each group has the form:

viewName[0],viewName[1],...viewName[n], where viewName[i] is the name of a view file in the 'views' folder, without its extension;

each group represents a view—that has children (subviews)—in the depth above that depth;

trace means show the trace tree (tracing can also be forced by setting $g_alwaysDoTrace in ccViews.php).

Each trace item has the form:


or, if the view is loaded using viewByName():

|name: viewName

where '|' indicates the depth.

The CCViews Server

The CCViews Viewer (ccViewsViewer.php) works with the CCViews Server (ccViewsServer.php) to let you share your views with others. It requires that the 'zip' utility (available at info-zip.org) be callable from PHP via exec().