Contao\Model::__construct PHP Метод

__construct() публичный Метод

Load the relations and optionally process a result set
public __construct ( Result $objResult = null )
$objResult Contao\Database\Result An optional database result
    public function __construct(Database\Result $objResult = null)
    {
        $this->arrModified = array();
        $objDca = \DcaExtractor::getInstance(static::$strTable);
        $this->arrRelations = $objDca->getRelations();
        if ($objResult !== null) {
            $arrRelated = array();
            $arrData = $objResult->row();
            // Look for joined fields
            foreach ($arrData as $k => $v) {
                if (strpos($k, '__') !== false) {
                    list($key, $field) = explode('__', $k, 2);
                    if (!isset($arrRelated[$key])) {
                        $arrRelated[$key] = array();
                    }
                    $arrRelated[$key][$field] = $v;
                    unset($arrData[$k]);
                }
            }
            $objRegistry = \Model\Registry::getInstance();
            $this->setRow($arrData);
            // see #5439
            $objRegistry->register($this);
            // Create the related models
            foreach ($arrRelated as $key => $row) {
                $table = $this->arrRelations[$key]['table'];
                /** @var static $strClass */
                $strClass = static::getClassFromTable($table);
                $intPk = $strClass::getPk();
                // If the primary key is empty, set null (see #5356)
                if (!isset($row[$intPk])) {
                    $this->arrRelated[$key] = null;
                } else {
                    $objRelated = $objRegistry->fetch($table, $row[$intPk]);
                    if ($objRelated !== null) {
                        $objRelated->mergeRow($row);
                    } else {
                        /** @var static $objRelated */
                        $objRelated = new $strClass();
                        $objRelated->setRow($row);
                        $objRegistry->register($objRelated);
                    }
                    $this->arrRelated[$key] = $objRelated;
                }
            }
        }
    }