FoxSecrets
Active member
I have a table like this:
I can check if values exists separately (like below), but how can I check if both columns values exists in the same row?
e.g. I want to check if the set user1 and option Y exists.
username | option |
user1 | X |
user1 | Y |
user1 | Z |
user2 | X |
user2 | Y |
I can check if values exists separately (like below), but how can I check if both columns values exists in the same row?
e.g. I want to check if the set user1 and option Y exists.
Code:
$username = $this->filter('username', 'str');
$username_exists = $this->assertUsernameExists('FOX\MyApp:Class', $username);
if (!$username_exists) {
throw $this->exception(
$this->error(\XF::phrase('admin.username_not_valid'))
);
}
public function assertUsernameExists($identifier, $id, $with = null, $phraseKey = null) {
return $this->assertRecordExistsByUnique($identifier, $id, 'user_name', $with, $phraseKey);
}
public function assertRecordExistsByUnique($identifier, $id, $uniqueColumn = null, $with = null, $phraseKey = null) {
if ($uniqueColumn === null) {
$record = $this->em()->find($identifier, $id, $with);
} else {
$record = $this->em()->findOne($identifier, [$uniqueColumn, '=', $id], $with);
}
return $record;
}
Last edited: