本文整理匯總了PHP中Pimcore\Model\Object::getResource方法的典型用法代碼示例。如果您正苦於以下問題:PHP Object::getResource方法的具體用法?PHP Object::getResource怎麽用?PHP Object::getResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Pimcore\Model\Object
的用法示例。
在下文中一共展示了Object::getResource方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getById
/**
* @param integer $id
* @return static
*/
public static function getById($id)
{
$id = intval($id);
if ($id < 1) {
return null;
}
$cacheKey = "object_" . $id;
try {
$object = \Zend_Registry::get($cacheKey);
if (!$object) {
throw new \Exception("Object\\AbstractObject: object in registry is null");
}
} catch (\Exception $e) {
try {
if (!($object = Cache::load($cacheKey))) {
$object = new Model\Object();
$typeInfo = $object->getResource()->getTypeById($id);
if ($typeInfo["o_type"] == "object" || $typeInfo["o_type"] == "variant" || $typeInfo["o_type"] == "folder") {
$mappingName = "";
if ($typeInfo["o_type"] == "folder") {
$mappingName = "\\Pimcore\\Model\\Object\\Folder";
} else {
$mappingName = "\\Pimcore\\Model\\Object\\" . ucfirst($typeInfo["o_className"]);
}
// check for a mapped class
$concreteClassName = Tool::getModelClassMapping($mappingName);
$object = new $concreteClassName();
\Zend_Registry::set($cacheKey, $object);
$object->getResource()->getById($id);
Cache::save($object, $cacheKey);
} else {
throw new \Exception("No entry for object id " . $id);
}
} else {
\Zend_Registry::set($cacheKey, $object);
}
} catch (\Exception $e) {
\Logger::warning($e->getMessage());
return null;
}
}
// check for type
$staticType = get_called_class();
if ($staticType != 'Pimcore\\Model\\Object\\Concrete' && $staticType != 'Pimcore\\Model\\Object\\AbstractObject') {
if (!$object instanceof $staticType) {
return null;
}
}
if (!$object) {
return null;
}
return $object;
}