string(19) "ViewArticleOrg.html"
Published 2006-07-28 00:00:00
<?php
// set up the include path to work! - our project, and our private pear install
ini_set('include_path',
realpath(dirname(__FILE__)) . ":"
. PATH_SEPARATOR . realpath(dirname(__FILE__)) . '/pear'
);
require_once 'HTML/FlexyFramework.php';
new HTML_FlexyFramework(array(
// all of these are available via HTML_FlexyFramework::get()->**section**
'project' => 'FlexyCash', // our project name
'FlexyCash' => array( // our project varoable
// put project options in here..
),
// set up the database connection + path to dataobjects.
'DB_DataObject' => array(
'database' => 'mysql://user:@localhost/gnucash', // fill in the correct details here!
'schema_location' => 'FlexyCash/DataObjects',
'class_location' => 'FlexyCash/DataObjects',
'require_prefix' => 'FlexyCash/DataObjects/',
'class_prefix' => 'FlexyCash_DataObjects_',
//'quote_identifiers' = 1
),
// any other stuff can go here..
));
<?php
class FlexyCash extends HTML_FlexyFramework_Page
{
var $template = 'welcome.html';
function getAuth()
{
return true; // everyone is allowed here!
}
function get($str)
{
// if we get a url that is not handled throw a 404 error page.
if (strlen($str)) {
echo "404 - not allowed";
// HTML_FlexyFramework::run('Error/404');
exit;
}
}
function post($str)
{
// if we get a url that is not handled throw a 404 error page.
if (strlen($str)) {
echo "404 - not allowed";
// HTML_FlexyFramework::run('Error/404');
exit;
}
}
}
/var/www/flexycash/FlexyCash/templates/master.html- our simple example is this. - just put the header text in there, and the outputBody():h call.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>FlexyCash - {title}</title>
<style> </style>
</head>
<body>
{outputBody():h}
</body>
</html>
/var/www/flexycash/FlexyCash/templates/welcome.htmlagain with some simple contents
Hello World <BR/>
root= {rootURL} <BR/>
base= {baseURL}
magic quotes is enabled add the line
php_value magic_quotes_gpc 0
to your .htaccess file
(Apache has to be configured to "AllowOverride Options AuthConfig" for the directory)
[DB_DataObject]run createTables on it.
database = mysql://user:@localhost/gnucash
schema_location = /var/www/flexycash/FlexyCash/DataObjects
class_location = /var/www/flexycash/FlexyCash/DataObjects
require_prefix = FlexyCash/DataObjects/
class_prefix = FlexyCash_DataObjects_
debug = 1
php -d include_path=/var/www/flexycash/pear \This should generate all the dataobjects for your project
/var/www/flexycash/pear/DB/DataObject/createTables.php /tmp/create_flexycash.ini
// from class FlexyCashCreate the code in the DataObject. - this creates a nested array of dataobjects showing the tree of the accounts. (only works on PHP5, as object now get passed by reference, rather than by copy)
// in get() method:
$this->loadAccounts();
var $accountsArray;
function loadAccounts()
{
$ac = DB_DataObject::factory('account');
$this->accountsArray = $ac->loadAccountsTree();
function loadAccountsTree()
{
$this->orderBy('name');
$this->find();
$ar = array();
while ($this->fetch()) {
if (!isset($parents[$this->parent])) {
$parents[$this->parent] = array();
}
$parents[$this->parent][] = clone($this);
}
foreach($parents[0] as $id => $obj) {
$this->buildTree($obj, $parents);
}
return $parents[0];
}
public $children;
function buildTree($obj, $parents)
{
$obj->children = !empty($parents[$obj->id]) ? $parents[$obj->id] : array();
foreach($obj->children as $id => $sobj) {
$this->buildTree($sobj, $parents);
}
}
<ul class="account-list">
<li flexy:foreach="accountsArray,account">
{account.toHtmlLi(baseURL):h}
</li>
</ul>
function toHtmlLi($baseurl)Now we can visit the home page again and see a list of the accounts as a unordered list.
{
$ret = '<a href="'. htmlspecialchars($baseurl). '/Account/'. $this->id . '.html">' .
htmlspecialchars($this->name) . '</a>';
if (empty($this->children)) {
return $ret;
}
$ret .= '<ul>';
foreach($this->children as $c) {
$ret .= '<li>'. $c->toHtmlLi($baseurl) . "</li>\n";
}
return $ret . '</ul>';
}