Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

TWIG problems?

posted by miker 9 years ago

Greetings all!

Has anyone had any luck using Flourish with TWIG?

The following returns:

Fatal error: Class 'fDatabase' not found in /Applications/MAMP/htdocs/local-ports/clients/loni/tests-flourish.php on line 21

<?php
// twig 0.9.10
// flourish r949
session_start();

require_once($_SERVER['DOCUMENT_ROOT'] . '/../inc-framework/init.php');  // load flourish

require_once dirname(__FILE__).'/lib/Twig/Autoloader.php';
Twig_Autoloader::register();

// set up Twig
$loader = new Twig_Loader_Filesystem('template');
$twig = new Twig_Environment($loader, array(
  'cache' => 'cache', 'auto_reload' => true, 'debug' => false  
));

require_once('Connections/db.php'); 
require_once('includes/functions.php');

if (!isset($bindings['mainNavigation'])) {
    $mysql_db  = new fDatabase('mysql', $database_db, $username_db, $password_db, $hostname_db); // connect to database
    $result = $mysql_db->query("SELECT * FROM menu WHERE menu.menuPublish ='y' AND menu.menuDelete = 'n' ORDER BY menu.menuSort ASC");
    
    $bindings['mainNavigation'] = array();  // create the menu array
    
    foreach ($result as $row) {
		$bindings['mainNavigation'][] = array('url' => $row['menuLink'], 'title' => $row['menuText'], 'copy' => $row['menuText']);
    }

	var_dump($bindings);
}
?>

Works fine if I pull all TWIG references out.

I don't know for sure, but I would suspect that Twig_Autoloader::register(); is using spl_autoload_register(), which will disable the __autoload() function. To fix this, rename your __autoload() function to my_autoload and call spl_autoload_register().

// Your renamed __autoload() function
function my_autoload($class) {
    // ....
}
spl_autoload_register('my_autoload');
posted by wbond 9 years ago