$config для конструктора объекта, создаваемого в yii2tech/embedded
Primary tabs
В конструкторе класса вложенного документа необходимо указать среди аргументов $config и передать его в конструктор родительского класса. Иначе объект создаваться не будет, по крайней мере, методами из yii2tech/embedded. Объекты создаются по данным, переданным в этом массиве.
class Abcd extends Model //... { function __construct($user = null, $config = []) { parent::__construct($config); //... }
class Object implements Configurable { /** * Returns the fully qualified name of this class. * @return string the fully qualified name of this class. */ public static function className() { return get_called_class(); } $config в коде родительского класса: <pre class="brush: php"> /** * Constructor. * The default implementation does two things: * * - Initializes the object with the given configuration `$config`. * - Call [[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. * * @param array $config 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(); }</pre>
- Log in to post comments
- 2315 reads