CI_Upload::initialize PHP Method

initialize() public method

Initialize preferences
public initialize ( array $config = [], boolean $reset = TRUE ) : CI_Upload
$config array
$reset boolean
return CI_Upload
    public function initialize(array $config = array(), $reset = TRUE)
    {
        $reflection = new ReflectionClass($this);
        if ($reset === TRUE) {
            $defaults = $reflection->getDefaultProperties();
            foreach (array_keys($defaults) as $key) {
                if ($key[0] === '_') {
                    continue;
                }
                if (isset($config[$key])) {
                    if ($reflection->hasMethod('set_' . $key)) {
                        $this->{'set_' . $key}($config[$key]);
                    } else {
                        $this->{$key} = $config[$key];
                    }
                } else {
                    $this->{$key} = $defaults[$key];
                }
            }
        } else {
            foreach ($config as $key => &$value) {
                if ($key[0] !== '_' && $reflection->hasProperty($key)) {
                    if ($reflection->hasMethod('set_' . $key)) {
                        $this->{'set_' . $key}($value);
                    } else {
                        $this->{$key} = $value;
                    }
                }
            }
        }
        // if a file_name was provided in the config, use it instead of the user input
        // supplied file name for all uploads until initialized again
        $this->_file_name_override = $this->file_name;
        return $this;
    }

Usage Example

Example #1
0
 function initialize($params = array())
 {
     $CI =& get_instance();
     if (!empty($params['field'])) {
         $this->field = $params['field'];
     }
     parent::initialize($params);
 }
All Usage Examples Of CI_Upload::initialize