Страница 1 из 1

о валидации...

Добавлено: 2019.04.10, 10:07
Maxim Glushko

Код: Выделить всё

public function rules() {
        return [
        	// ...
		['parent_id', 'exist', 'targetClass' => self::class, 'targetAttribute' => ['parent_id' => 'id'],
                	'message' => 'Нет статьи с таким id', 'when' => function($value) {return !$value;}],
		['next_id', 'exist', 'targetClass' => self::class, 'targetAttribute' => ['next_id' => 'id'],
			'message' => 'Нет статьи с таким id', 'when' => function($value) {return !$value;}],
		['prev_id', 'exist', 'targetClass' => self::class, 'targetAttribute' => ['prev_id' => 'id'],
			'message' => 'Нет статьи с таким id', 'when' => function($value) {return !$value;}],
		// ...
	];
}
Как это упростить, сделав одной строкой?

Код: Выделить всё

public function rules() {
        return [
        	// ...
		[['parent_id', 'next_id', 'prev_id'], 'exist',
			'targetClass' => self::class, 'targetAttribute' => ['???' => 'id'],
                	'message' => 'Нет статьи с таким id', 'when' => function($value) {return !$value;}],
		// ...
	];
}

Re: о валидации...

Добавлено: 2019.04.10, 11:51
SiZE

Код: Выделить всё

'targetAttribute' => 'id'