Was sad to see Yii2’s getOldAttributes() did not have to ability to limit based on a provided array; whereas getAttributes() does take an array to limit the returned attributes. So I whipped this up right quick:
/** * @param array $array * * @return array */ public function getOldAttributes($array = []) { $returnData = parent::getOldAttributes(); if (!empty($array)) { $returnData = array_intersect($array, $returnData); } return $returnData; }
Simple little thing but super handy.