CConfiguration
| Package |
system.collections |
| Inheritance |
class CConfiguration »
CMap »
CComponent |
| Implements |
Countable, ArrayAccess, Traversable, IteratorAggregate |
| Since |
1.0 |
| Version |
$Id: CConfiguration.php 1678 2010-01-07 21:02:00Z qiang.xue $ |
CConfiguration represents an array-based configuration.
It can be used to initialize an object's properties.
The configuration data may be obtained from a PHP script. For example,
<?php
return array
(
'name'=>'My Application',
'defaultController'=>'index',
);
?>
Use the following code to load the above configuration data:
$config=new CConfiguration('path/to/config.php');
To apply the configuration to an object, call
applyTo().
Each (key,value) pair in the configuration data is applied
to the object like: $object->$key=$value.
Since CConfiguration extends from
CMap, it can be
used like an associative array. See
CMap for more details.
Method Details
|
public void __construct(mixed $data=NULL)
|
| $data |
mixed |
if string, it represents a config file (a PHP script returning the configuration as an array);
If array, it is config data. |
Constructor.
|
public void applyTo(object $object)
|
| $object |
object |
object to be applied with this configuration |
Applies the configuration to an object.
Each (key,value) pair in the configuration data is applied
to the object like: $object->$key=$value.
|
public static mixed createObject(mixed $config)
|
| $config |
mixed |
the configuration. It can be either a string or an array. |
| {return} |
mixed |
the created object |
Creates an object and initializes it based on the given configuration.
NOTE: this method has been deprecated since version 1.0.1.
Please use Yii::createComponent, instead.
|
public void loadFromFile(string $configFile)
|
| $configFile |
string |
configuration file path (if using relative path, be aware of what is the current path) |
Loads configuration data from a file and merges it with the existing configuration.
A config file must be a PHP script returning a configuration array (like the following)
return array
(
'name'=>'My Application',
'defaultController'=>'index',
);
|
public string saveAsString()
|
| {return} |
string |
the string representation of the configuration |
Saves the configuration into a string.
The string is a valid PHP expression representing the configuration data as an array.