Pimcore\Model\Asset::getByPath PHP Method

getByPath() public static method

Static helper to get an asset by the passed path
public static getByPath ( string $path ) : Asset | Archive | Audio | Document | Folder | Image | Text | Unknown | Video
$path string
return Asset | Archive | Audio | Document | Folder | Image | Text | Unknown | Video
    public static function getByPath($path)
    {
        $path = Element\Service::correctPath($path);
        try {
            $asset = new Asset();
            if (Tool::isValidPath($path)) {
                $asset->getDao()->getByPath($path);
                return self::getById($asset->getId());
            }
        } catch (\Exception $e) {
            Logger::warning($e->getMessage());
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * @param string $name
  * @return DAV\INode|void
  * @throws DAV\Exception\NotFound
  */
 function getChild($name)
 {
     $nameParts = explode("/", $name);
     $name = File::getValidFilename($nameParts[count($nameParts) - 1]);
     //$name = implode("/",$nameParts);
     if (is_string($name)) {
         $parentPath = $this->asset->getFullPath();
         if ($parentPath == "/") {
             $parentPath = "";
         }
         if (!($asset = Asset::getByPath($parentPath . "/" . $name))) {
             throw new DAV\Exception\NotFound('File not found: ' . $name);
         }
     } else {
         if ($name instanceof Asset) {
             $asset = $name;
         }
     }
     if ($asset instanceof Asset) {
         if ($asset->getType() == "folder") {
             return new Asset\WebDAV\Folder($asset);
         } else {
             return new Asset\WebDAV\File($asset);
         }
     }
     throw new DAV\Exception\NotFound('File not found: ' . $name);
 }
All Usage Examples Of Pimcore\Model\Asset::getByPath