XF 2.2 How to check if two values from table exists

FoxSecrets

Active member
I have a table like this:

usernameoption
user1X
user1Y
user1Z
user2X
user2Y

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:
It worked, thanks!

Code:
$match = $this->em()->findOne('FOX\MyApp:Class', ['username' =>$username, 'option' =>$option]);
 
Last edited:
Top Bottom