Autoload solution to __PHP_Incomplete_Class - Re: [PEAR] Can youserialize a Formbuilder object?
| From: | Andrew Wooldridge | Date: | Wed, 29 Jun 2005 17:02:39 +0000 |
| Subject: | Autoload solution to __PHP_Incomplete_Class - Re: [PEAR] Can youserialize a Formbuilder object? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-19826@lists.php.net to get a copy of this message | ||
Uhh that didn't work.
require_once('/usr/lib/php/HTML/QuickForm/Controller.php');
require_once('/usr/lib/php/DB/DataObject/FormBuilder.php');
require_once('/usr/lib/php/HTML/QuickForm.php');
require_once('DB/DataObject/FormBuilder/QuickForm.php');
// Load some default action handlers
require_once( 'HTML/QuickForm/Action/Next.php');
require_once( 'HTML/QuickForm/Action/Back.php');
require_once( 'HTML/QuickForm/Action/Jump.php');
require_once( 'HTML/QuickForm/Action/Display.php');
require_once( 'HTML/QuickForm/Action/Submit.php');
//a handy string function that returns everything in the string after
your query
//example after('abc','abcdef'); returns 'def'
function after ($thisone, $inthat)
{
if (!is_bool(strpos($inthat, $thisone)))
return substr($inthat,
strpos($inthat,$thisone)+strlen($thisone));
};
//function __autoload($classname)
//this function gets called when a class is come across that has not
been included yet
//there are two locations for classes that this program uses.
//the first is the DataObjects directory containing the autogenerated
DataObject classes
//that were created with createTables.php
//and prepended with class_prefix from DataObject.ini
//the second is the PEAR library repository. Per PEAR conventions, the
class name will
//determine where the file is located in the PEAR hierarchy.
//example HTML_QuickForm_Header class is located at the path
HTML/QuickForm/header.php
// NOTE: required classes above are the ones that don't follow this
convention.
function __autoload($className)
{
$config = parse_ini_file('DataObject.ini',TRUE);
$dataObjectClassPrefix =
{$config["DB_DataObject"]["class_prefix"]};
$dataObjectDirectoryPath =
{$config["DB_DataObject"]["class_location"]};
#echo $className."\n".$dataObjectClassPrefix."\n".strpos($className,
$dataObjectClassPrefix)."<br>\n\n\n";
if (!(strpos($className, $dataObjectClassPrefix) === false))
{
require_once
$dataObjectDirectoryPath.after($dataObjectClassPrefix,$className) . '.php';
}
else
{
require_once str_replace('_', '/', $className).'.php';
}
}
?>