My Application works with Third Party Applications. The Thirdparty Application is a Library Class, which is locaded in application/libraries/NAMEOFTHECLASS/main.php.
I have a Library the modulehandler which has the job to handle the ThirdParty-Classes.
The Third Party Class looks like this:
class main {
var $name;
var $description;
var $saphir;
var $location;
public function init($config = array()) {
$this->name = $config['name'];
$this->description = $config['description'];
$this->saphir =& get_instance();
$this->location = $config['location'];
}
public function getFormElements() {
$html = $this->saphir->load->file($this->location.'/tpl/main.html',true);
$this->saphir->load->library('parser');
$data = array(
'name' => $this->name,
'description' => $this->description
);
$html = $this->saphir->parser->parse_string($html, $data, TRUE);
return $html;
}
public function validation($post_data)
{
$array = explode(',', $post_data);
if($post_data != is_array($array) )
return array("error" => array("name" => $this->name, "message" => "Bitte geben Sie nur eine Kommagetrennte Liste an"));
}
public function handleData($post_data) {
$array = explode(',', $post_data);
$return = array();
foreach($array as $key => $val) {
array_push($return, array("data" => $val));
}
return $return;
}
}
In the Module Handler i load in a foreach every thirdparty class which i need and call a function.
Zb in my ModuleHandler Class here is the method to get Form Elements from the Thirdparty Scripts:
private function getForm()
{
$form_data = array();
foreach($this->schema as $schema) {
$config = array("type" => $schema['type'], "name" => $schema['name'], "description" => $schema['description'], 'location' => 'application/libraries/thirdparty/cm_system/'.$schema['type']);
$type = $schema['type'];
if($this->edit) {
$value = $this->info;
$val = array();
foreach($value->ELEMENT as $element)
{
$holder = (string)$element;
array_push($val, $holder);
}
$value = $val;
}
else {
$value = "";
}
$ins = $this->CI->load->library('thirdparty/cm_system/'.$type.'/main');
$this->CI->main->init($config);
$form_elements = $this->CI->main->getFormElements($value);
array_push($form_data, $form_elements);
}
return $form_data;
}
The problem is, that every thirdparty Class has the name main. And i get the error that i cant redeclare class main. Is there a way to unset the loaded class?
I tried it already with unset. But it dont works.