<?
/*
* Hello World 2
*
* AModules3 may provide multiple different Api classes you can use. At the moment of writing it
* have only 2 usable Api clasess:
* ApiStd
* ApiAdmin
*
* All api clases are inherited from ApiBase. It's up to you which Api you are using. ApiAdmin would
* allow you to use pre-defined templates, it would allow you to use many existing controls for
* building administration or control system. ApiStd is more lightweight and allows you to do
* things your way. Here we'll demonstrate how to use ApiStd.
*
* All classes work with template system which is specially designed for the library needs: SMlite.
* For SMlite introduction, read doc/SMlite-introduction.txt
*
* In this example we will be using template file: "hw". This file by default is searched inside
* "template" subdirectory.
*
* When you initialize API class you have to specify "realm". It's important to have unique realm
* for each installation of your application on your server. Otherwise application may accidentaly
* share the same session variables. If you want those application to be "under the same roof",
* I guess you can use equal realms. 'hw' is a suitable realm for this application. I don't suggest
* to use spaces or anything else except characters, digits, underscopes and dashes.
*
* And final note - you do not need to include any classes. They are automatically included when
* you use them, this is a feature of PHP5. Class Foo_Bar will be searched inside file Foo/Bar.php.
*
* See inline comments
*/
include '../../trunk/loader.php';
/*
* loader.php includes static.php file automatically. It is going to define some static functions
* such as low level for error handling: exception visualiser, backtrack generator and handlers.
*
* If you are willing to customize any of those functions, all you have to do is to define them
* BEFORE you include loader.php. By doing this you could:
* - disable error output for production systems,
* - make custom erorr reporting framework, for instance you can log them into syslog
* or send through jabber,
* - customize default behavor of class->filename translation by redefining __autoload function.
*/
$api = new ApiWeb('hw2');
/*
* I suggest using $api for Api class. Nowhere in the library we reference any global variables, but
* if we all use $api, we'll maintain a common style.
*
* For an application you'll have to initialize it. There are two ways:
* - create your own Api class, redefine init() method (if you use ApiAdmin, you should redefine
* initAdmin())
* - use default class, initialize right after you "new" it.
*
* if you redefine init() call parent::init() BEFORE doing anything.
*
* ApiWeb::init() does the following
* - initialize session
* - send headers
* - put _GET['page'] into $api->page
*
* ApiAdmin::init()
* - calls ApiBase::init()
* - tries to load config.php
* - defines DTP (database table prefix)
* - sets up $api->config['layout'] if it wasn't defined
* - initializes Api's template
* - creates Index page which is default
*
* We use ApiWeb for simple applications like 'Hello World' :)
*/
$api->template = $api->add('SMlite')->loadTemplate('hw'); // using file templates/hw.html
/*
* Here we assign template to our application. This template is a "generic" one. You have to
* define several regions inside this generic template like:
* - page title
* - page content region
* - optionally menu region or sidebar regions
*
* In our hw template we will have title region and content region. Our primary task would
* be to fill those regions with dynamic data.
*/
/*
* You might feel an urge to rename templates into .tpl, but i advise to use .html files. There is
* a reason for that. SMlite is designed to allow you to leave the look of the page the same even
* after you insert the tags. When using other template engines, you won't be able to look
* on your template through browser once you start using it inside your application. Not in our
* case, you will be able to look at the templates and even edit them. You can allow your designer
* to edit them even if he is not aware of SMlite tags being in there, he'll be able to make
* modifications and see them on-site right after the change. That's why I suggest you to preserve
* .html extention.
*/
$api->template->set('page_title','Hello world application');
$api->template->set('page_content','Dynamic Hello world ('.rand().')');
/*
* This is a simple way to "fill regions" inside your api template. Assign them to string.
*/
$api->main();
$api->template->render();
/*
* main() does the submited form handling and rendering
*/