yii\base\Object::__construct PHP Method

__construct() public method

The default implementation does two things: - Initializes the object with the given configuration $config. - Call Object::init. If this method is overridden in a child class, it is recommended that - the last parameter of the constructor is a configuration array, like $config here. - call the parent implementation at the end of the constructor.
public __construct ( array $config = [] )
$config array name-value pairs that will be used to initialize the object properties
    public function __construct($config = [])
    {
        if (!empty($config)) {
            Yii::configure($this, $config);
        }
        $this->init();
    }

Usage Example

示例#1
0
 /**
  * @param string|mixed[] $config the configuration of [[\romkaChev\yii2\swiper\Slide]]
  *                               You can create slide just from string
  *                               For example:
  *
  *                               ~~~
  *                                 $slide = new \romkaChev\yii2\swiper\Slide('slide content');
  *                               ~~~
  *
  *
  *                               Also you can create slide from array or strings and
  *                               they will be merged into one string
  *                               For example:
  *
  *                               ~~~
  *                                $slide = new \romkaChev\yii2\swiper\Slide([
  *                                    'content' => [
  *                                        '<h1>Title</h1>',
  *                                        '<h3>Subtitle</h3>',
  *                                        '<p>Main content</p>'
  *                                    ]
  *                                ]);
  *                               ~~~
  *
  * @see \romkaChev\yii2\swiper\Slide::$background
  * @see \romkaChev\yii2\swiper\Slide::$hash
  * @see \romkaChev\yii2\swiper\Slide::$content
  */
 public function __construct($config = [])
 {
     $config = is_string($config) ? [self::CONTENT => $config] : $config;
     $config[self::CONTENT] = ArrayHelper::getValue($config, self::CONTENT, null);
     $config[self::CONTENT] = is_array($config[self::CONTENT]) ? implode('', $config[self::CONTENT]) : $config[self::CONTENT];
     parent::__construct($config);
 }
All Usage Examples Of yii\base\Object::__construct