I have a configuration.php as a separate file.IT contat bellow pardFactory class with 11 variables.I need to assign their values from array.that $ConfigData is in another file.How would i do this?
CLASS
<?php
class PardFactory {
public $TITLE = 'Sri lanka Accommodation';
public $ONLINE = 'Site Online';
public $OFFLINE = '';
public $EMAIL = '';
public $METADESCRIPTION = '';
public $METAKEYWORDS = '';
public $COPYRIGHT = '';
public $HOST = '';
public $DATABASE = '';
public $USERNAME = '';
public $PASSWORD = '';
}
?>
ARRAY
$ConfigData = array($adminConfig->TITLE,
$adminConfig->ONLINE,
$adminConfig->OFFLINE,
$adminConfig->EMAIL,
$adminConfig->METADESCRIPTION,
$adminConfig->METAKEYWORDS,
$adminConfig->COPYRIGHT,
$adminConfig->HOST,
$adminConfig->DATABASE,
$adminConfig->USERNAME,
$adminConfig->PASSWORD);
I want to pass array values to class values.
Also, I need to have only that above pardFactory class in that configuration.php. IF i'd do like above i need to include pardFactory class to the configuration.php first. I need to have this file like joomla configuration.php file
Do this create an object of class file like this:
$obj = new PardFactory($ConfigData);
And create a constructor
function __construct($config) {
$this->TITLE = $config->TITLE;
$this->ONLINE = $config->ONLINE;
}
and so on.
Try something like this
$obj = new PardFactory($ConfigData);
class PardFactory {
public function __construct(Array $config=array()){
foreach($config as $key => $value){
$this->{$key} = $value;
}
}
}