Contao\Model\Registry::fetch PHP Method

fetch() public method

Fetch a model by table name and primary key
public fetch ( string $strTable, mixed $varKey, string $strAlias = null ) : Model | null
$strTable string The table name
$varKey mixed The key
$strAlias string An optional alias
return Contao\Model | null The model or null
    public function fetch($strTable, $varKey, $strAlias = null)
    {
        /** @var Model $strClass */
        $strClass = \Model::getClassFromTable($strTable);
        $strPk = $strClass::getPk();
        // Search by PK (most common case)
        if ($strAlias === null || $strAlias == $strPk) {
            if (isset($this->arrRegistry[$strTable][$varKey])) {
                return $this->arrRegistry[$strTable][$varKey];
            }
            return null;
        }
        // Try to find the model by one of its aliases
        return $this->fetchByAlias($strTable, $strAlias, $varKey);
    }