Pimcore\Model\Object\ClassDefinition\CustomLayout::getById PHP Method

getById() public static method

public static getById ( $id ) : mixed | null | CustomLayout
$id
return mixed | null | CustomLayout
    public static function getById($id)
    {
        if ($id === null) {
            throw new \Exception("CustomLayout id is null");
        }
        $cacheKey = "customlayout_" . $id;
        try {
            $customLayout = \Zend_Registry::get($cacheKey);
            if (!$customLayout) {
                throw new \Exception("Custom Layout in registry is null");
            }
        } catch (\Exception $e) {
            try {
                $customLayout = new self();
                $customLayout->getDao()->getById($id);
                Object\Service::synchronizeCustomLayout($customLayout);
                \Zend_Registry::set($cacheKey, $customLayout);
            } catch (\Exception $e) {
                Logger::error($e);
                return null;
            }
        }
        return $customLayout;
    }

Usage Example

 /**
  * Loads a list of custom layouts for the specified parameters, returns an array of Object\ClassDefinition\CustomLayout elements
  *
  * @return array
  */
 public function load()
 {
     $layouts = array();
     $layoutsRaw = $this->db->fetchCol("SELECT id FROM custom_layouts" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($layoutsRaw as $classRaw) {
         $layouts[] = Model\Object\ClassDefinition\CustomLayout::getById($classRaw);
     }
     $this->model->setLayoutDefinitions($layouts);
     return $layouts;
 }
All Usage Examples Of Pimcore\Model\Object\ClassDefinition\CustomLayout::getById