Forum Moderators: coopster
main_class.php:
class class_pi{
function include_field_class($fieldtype){
$class_name = 'class_fieldtype_'.$fieldtype;
if(!class_exists($class_name)){
require_once($fieldtype.'.php');
}
function get_field_output($fieldtype){
$class_name = 'class_fieldtype_'.$fieldtype;
if(class_exists($class_name)){
echo 'class exists';
}
$class_fieldtype = new $class_name();
echo $class_fieldtype->test();
}
}
select.php:
class class_fieldtype_select extends class_pi{
function test(){
return 'test';
}
}
edit_page.php:
$fieldtype = 'select';
//include the fields class file
$class_pi->include_field_class($fieldtype);
// get the field-classname
$class_name = 'class_fieldtype_'.$fieldtype;
//make instance of the class
$class_plugin = new $class_name();
/do something, this works
echo $class_plugin->test();
Grrrr! I've been on this all afternoon and its driving me nuts. Please help me.
Of is from within the main_class.php in another member function? In which case you do use the something like
$this->get_field_output('select');
I'm not entirely new to working with classes, but this thing I am totally stuck on.
I tried the code here I do not see anything.
here it is in a single file.
class class_pi{
function include_field_class($fieldtype){
$class_name = 'class_fieldtype_'.$fieldtype;
if(!class_exists($class_name)){
//require_once($fieldtype.'.php');
}
}
function get_field_output($fieldtype){
$class_name = 'class_fieldtype_'.$fieldtype;
if(class_exists($class_name)){
echo 'class exists<br />';
}
$class_fieldtype = new $class_name();
echo $class_fieldtype->test();
}
}
//select.php:
class class_fieldtype_select extends class_pi{
function test(){
return 'test';
}
}
//edit_page.php:
$fieldtype = 'select';
//include the fields class file
$class_pi = new class_pi();
$class_pi->include_field_class($fieldtype);
$class_pi->get_field_output('select');
// get the field-classname
$class_name = 'class_fieldtype_'.$fieldtype;
//make instance of the class
$class_plugin = new $class_name();
//do something, this works
//echo $class_plugin->test();
I get the "test" via the $class_pi->get_field_output('select');
well doesn't seem to be the code that you posted so far. It may be something else, is the prototype class file included before the call?