Pimcore\Model\Document\Service::getByUrl PHP Method

getByUrl() public static method

public static getByUrl ( $url ) : Document
$url
return Pimcore\Model\Document
    public static function getByUrl($url)
    {
        $urlParts = parse_url($url);
        if ($urlParts["path"]) {
            $document = Document::getByPath($urlParts["path"]);
            // search for a page in a site
            if (!$document) {
                $sitesList = new Model\Site\Listing();
                $sitesObjects = $sitesList->load();
                foreach ($sitesObjects as $site) {
                    if ($site->getRootDocument() && (in_array($urlParts["host"], $site->getDomains()) || $site->getMainDomain() == $urlParts["host"])) {
                        if ($document = Document::getByPath($site->getRootDocument() . $urlParts["path"])) {
                            break;
                        }
                    }
                }
            }
        }
        return $document;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Returns the element data denoted by the given type and ID or path.
  */
 public function getSubtypeAction()
 {
     $idOrPath = trim($this->getParam("id"));
     $type = $this->getParam("type");
     if (is_numeric($idOrPath)) {
         $el = Element\Service::getElementById($type, (int) $idOrPath);
     } else {
         if ($type == "document") {
             $el = Document\Service::getByUrl($idOrPath);
         } else {
             $el = Element\Service::getElementByPath($type, $idOrPath);
         }
     }
     if ($el) {
         if ($el instanceof Asset || $el instanceof Document) {
             $subtype = $el->getType();
         } elseif ($el instanceof Object\Concrete) {
             $subtype = $el->getClassName();
         } elseif ($el instanceof Object\Folder) {
             $subtype = "folder";
         }
         $this->_helper->json(["subtype" => $subtype, "id" => $el->getId(), "type" => $type, "success" => true]);
     } else {
         $this->_helper->json(["success" => false]);
     }
 }