public one ( |
||
$db | the DB connection used to create the DB command. If `null`, the DB connection returned by [[modelClass]] will be used. | |
return | a single row of query result. Depending on the setting of [[asArray]], the query result may be either an array or an ActiveRecord object. `null` will be returned if the query results in nothing. |
public function one($db = null)
{
$row = parent::one($db);
if ($row !== false) {
$models = $this->populate([$row]);
return reset($models) ?: null;
} else {
return null;
}
}
public static function getActiveToken($token) { $activeQuery = new ActiveQuery(self::className()); $activeQuery->where('access_token = :token', [':token' => $token]); $activeQuery->andWhere('expires > now()'); $token = $activeQuery->one(); return $token; }