D
D
Dmitry Bay2015-11-30 11:05:20
PHP
Dmitry Bay, 2015-11-30 11:05:20

How to add to the parent array in the element class, or overwrite the current element arrays?

for example in code:

class Parent {
 public function rules()
    {
        return [
            'bioString' => ['bio', 'string'],
            'publicEmailPattern' => ['public_email', 'email'],
            'gravatarEmailPattern' => ['gravatar_email', 'email'],
            'websiteUrl' => ['website', 'url'],
            'nameLength' => ['name', 'string', 'max' => 255],
            'publicEmailLength' => ['public_email', 'string', 'max' => 255],
            'gravatarEmailLength' => ['gravatar_email', 'string', 'max' => 255],
            'locationLength' => ['location', 'string', 'max' => 255],
            'websiteLength' => ['website', 'string', 'max' => 255],
            'photoLength' => ['photo', 'string', 'max' => 200],
        ];
    }
}

class Child extends Parent {
 // вот тут в наследуемом элементе, нужно переписать один из элементов массива родителя либо дополнить другими элементами.
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sunrails, 2015-11-30
@kawabanga

class Child extends Parent {
 public function rules()
    {
        return array_merge(parent::rules(), [
            'bioString' => ['bio', 'string'],
            'publicEmailPattern' => ['public_email', 'email'],
        ]);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question