@Frank Wong,
which version of the code do you have? Line 922 in mine is a bracket-close.
You can run into this issue if you have specified a fully qualified path for ‘extensions_path’ in your datamapper config. Try defining it relative to APPPATH (so just ‘datamapper’ in your case) to work around it.
It can be fixed by adding an else:
if ( ! file_exists($file))
{
// existing code here
}
else
{
$ext = $name;
}
I am using DM 1.8.2 installed from sparks and CI 2.1.0.
This is the entire _load_extensions() function in datamapper.php
protected static function _load_extensions(&$extensions, $names)
{
$CI =& get_instance();
$class_prefixes = array(
0 => 'DMZ_',
1 => 'DataMapper_',
2 => $CI->config->item('subclass_prefix'),
3 => 'CI_'
);
foreach($names as $name => $options)
{
if( ! is_string($name))
{
$name = $options;
$options = NULL;
}
// only load an extension if it wasn't already loaded in this context
if(isset($extensions[$name]))
{
return;
}
if( ! isset($extensions['_methods']))
{
$extensions['_methods'] = array();
}
// determine the file name and class name
$file = DataMapper::$config['extensions_path'] . '/' . $name . EXT;
$file = ''; // TODO: FW - ugly hack to make loading extensions work. Need to remove when there is a fix.
if ( ! file_exists($file))
{
if(strpos($name, '/') === FALSE)
{
$file = APPPATH . DataMapper::$config['extensions_path'] . '/' . $name . EXT;
$ext = $name;
}
else
{
$file = APPPATH . $name . EXT;
$ext = array_pop(explode('/', $name));
}
if(!file_exists($file))
{
show_error('DataMapper Error: loading extension ' . $name . ': File not found.');
}
}
// load class
include_once($file);
// Allow for DMZ_Extension, DataMapper_Extension, etc.
foreach($class_prefixes as $index => $prefix)
{
if(class_exists($prefix.$ext))
{
if($index == 2) // "MY_"
{
// Load in the library this class is based on
$CI->load->library($ext);
}
$ext = $prefix.$ext;
break;
}
}
if(!class_exists($ext))
{
show_error("DataMapper Error: Unable to find a class for extension $name.");
}
// create class
if(is_null($options))
{
$o = new $ext(NULL, isset($this) ? $this : NULL);
}
else
{
$o = new $ext($options, isset($this) ? $this : NULL);
}
$extensions[$name] = $o;
// figure out which methods can be called on this class.
$methods = get_class_methods($ext);
foreach($methods as $m)
{
// do not load private methods or methods already loaded.
if($m[0] !== '_' &&
is_callable(array($o, $m)) &&
! isset($extensions['_methods'][$m])
) {
// store this method.
$extensions['_methods'][$m] = $name;
}
}
}
}
Is the sparks version 1.8.2 not the version everyone else is referring to?
Thanks.