Pimcore\Model\Asset::setId PHP Method

setId() public method

public setId ( integer $id )
$id integer
    public function setId($id)
    {
        $this->id = (int) $id;
        return $this;
    }

Usage Example

 /** end point for asset related data.
  * - get asset by id
  *      GET http://[YOUR-DOMAIN]/webservice/rest/asset/id/1281?apikey=[API-KEY]
  *      returns json-encoded asset data.
  * - delete asset by id
  *      DELETE http://[YOUR-DOMAIN]/webservice/rest/asset/id/1281?apikey=[API-KEY]
  *      returns json encoded success value
  * - create asset
  *      PUT or POST http://[YOUR-DOMAIN]/webservice/rest/asset?apikey=[API-KEY]
  *      body: json-encoded asset data in the same format as returned by get asset by id
  *              but with missing id field or id set to 0
  *      returns json encoded asset id
  * - update asset
  *      PUT or POST http://[YOUR-DOMAIN]/webservice/rest/asset?apikey=[API-KEY]
  *      body: same as for create asset but with asset id
  *      returns json encoded success value
  * @throws \Exception
  */
 public function assetAction()
 {
     $id = $this->getParam("id");
     $success = false;
     try {
         if ($this->isGet()) {
             $asset = Asset::getById($id);
             if (!$asset) {
                 $this->encoder->encode(array("success" => false, "msg" => "Asset does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST));
                 return;
             }
             $this->checkPermission($asset, "get");
             if ($asset instanceof Asset\Folder) {
                 $object = $this->service->getAssetFolderById($id);
             } else {
                 $light = $this->getParam("light");
                 $options = array("LIGHT" => $light ? 1 : 0);
                 $object = $this->service->getAssetFileById($id, $options);
                 $algo = "sha1";
                 $thumbnailConfig = $this->getParam("thumbnail");
                 if ($thumbnailConfig && $asset->getType() == "image") {
                     $checksum = $asset->getThumbnail($thumbnailConfig)->getChecksum($algo);
                     $object->thumbnail = (string) $asset->getThumbnail($thumbnailConfig);
                 } else {
                     $checksum = $asset->getChecksum($algo);
                 }
                 $object->checksum = array("algo" => $algo, "value" => $checksum);
                 if ($light) {
                     unset($object->data);
                 }
             }
             $this->encoder->encode(array("success" => true, "data" => $object));
             return;
         } else {
             if ($this->isDelete()) {
                 $asset = Asset::getById($id);
                 if ($asset) {
                     $this->checkPermission($asset, "delete");
                 }
                 $success = $this->service->deleteAsset($id);
                 $this->encoder->encode(array("success" => $success));
                 return;
             } else {
                 if ($this->isPost() || $this->isPut()) {
                     $data = file_get_contents("php://input");
                     $data = \Zend_Json::decode($data);
                     $type = $data["type"];
                     $id = null;
                     if ($data["id"]) {
                         $asset = Asset::getById($data["id"]);
                         if ($asset) {
                             $this->checkPermission($asset, "update");
                         }
                         $isUpdate = true;
                         if ($type == "folder") {
                             $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In", $data);
                             $success = $this->service->updateAssetFolder($wsData);
                         } else {
                             $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In", $data);
                             $success = $this->service->updateAssetFile($wsData);
                         }
                     } else {
                         if ($type == "folder") {
                             $class = "\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In";
                             $method = "createAssetFolder";
                         } else {
                             $class = "\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In";
                             $method = "createAssetFile";
                         }
                         $wsData = self::fillWebserviceData($class, $data);
                         $asset = new Asset();
                         $asset->setId($wsData->parentId);
                         $this->checkPermission($asset, "create");
                         $id = $this->service->{$method}($wsData);
                     }
                     if (!$isUpdate) {
                         $success = $id != null;
                     }
                     if ($success && !$isUpdate) {
                         $this->encoder->encode(array("success" => $success, "data" => array("id" => $id)));
                     } else {
                         $this->encoder->encode(array("success" => $success));
                     }
                     return;
                 }
             }
         }
     } catch (\Exception $e) {
         \Logger::error($e);
         $this->encoder->encode(array("success" => false, "msg" => (string) $e));
     }
     $this->encoder->encode(array("success" => false));
 }
All Usage Examples Of Pimcore\Model\Asset::setId