For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > July 2005 > Can't set DB_DataObject_FormBuilder options in DataObject.ini.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can't set DB_DataObject_FormBuilder options in DataObject.ini.
jp

2005-07-24, 8:39 pm

I am having trouble getting DB_DataObject_FormBuilder to read the options set
in DataObject.ini. I include the following file, config.php, in all files
that use DataObject_FormBuilder:

<?php
// this is the common configuration code - place in a general site wide
include file.
// the simple examples use parse_ini_file, which is fast and efficient.
// however you could as easily use wddx, xml or your own configuration array.
$ini_config = parse_ini_file('../includes/DataObject.ini',TRUE);

// this the code used to load and store DataObjects Configuration.
$options = & PEAR::getStaticProperty('DB_DataObject',
'options');

// because PEAR::getstaticProperty was called with and & (get by reference)
// this will actually set the variable inside that method (a quasi static
variable)
$options = $ini_config['DB_DataObject'];

// set FormBuilder options -- commented out as per changelog for
DataObject_FormBuilder 0.17.2
//$_DB_DATAOBJECT_FORMBUILDER['CONFIG'] =
$ini_config['DB_DataObject_FormBuilder']
;
?>

Uncommenting the $_DB_DATAOBJECT_FORMBUILDER['CONFIG'] =
$ini_config['DB_DataObject_FormBuilder']
line does not change the fact that
the options are not parsed. The only workaround that I have found is to add
the following two lines to the constructor of the DataObject_FormBuilder
class:

global $ini_config;
$config = $ini_config['DB_DataObject_FormBuilder']
;

I add these two lines here in the FormBuilder.php file (start quoting at line
888):

// Read in config
$vars = get_object_vars($this);
$defVars = get_class_vars(get_class($this));
$config =& PEAR::getStaticProperty('DB_DataObject_F
ormBuilder',
'options');

global $ini_config;
$config = $ini_config['DB_DataObject_FormBuilder']
;

if (!isset($config) || !is_array($config)) {
$config = array();
}
//read all config options into member vars
foreach ($config as $key => $value) {
if (in_array($key, $vars) && $key[0] != '_') {
if (isset($defVars[$key])
&& is_array($defVars[$key])
&& is_string($value)) {
$value = $this->_explodeArrString($value);
}
$this->$key = $value;
}
}
if (is_array($options)) {
reset($options);
while (list($key, $value) = each($options)) {
if (in_array($key, $vars) && $key[0] != '_') {
$this->$key = $value;
}
}
}

This is obviously not the way to get DB_DataObject_FormBuilder to read the
options from the file, but how does one do it then?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com