当前位置: 首页>>代码示例>>PHP>>正文


PHP Object::setId方法代码示例

本文整理汇总了PHP中Pimcore\Model\Object::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::setId方法的具体用法?PHP Object::setId怎么用?PHP Object::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pimcore\Model\Object的用法示例。


在下文中一共展示了Object::setId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: objectAction


//.........这里部分代码省略.........
             if ($id) {
                 $profile = $this->getParam("profiling");
                 if ($profile) {
                     $startTs = microtime(true);
                 }
                 $object = Object::getById($id);
                 if (!$object) {
                     $this->encoder->encode(array("success" => false, "msg" => "Object does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST));
                     return;
                 }
                 if ($profile) {
                     $timeConsumedGet = round(microtime(true) - $startTs, 3) * 1000;
                     $startTs = microtime(true);
                 }
                 $this->checkPermission($object, "get");
                 if ($profile) {
                     $timeConsumedPerm = round(microtime(true) - $startTs, 3) * 1000;
                     $startTs = microtime(true);
                 }
                 if ($object instanceof Object\Folder) {
                     $object = $this->service->getObjectFolderById($id);
                 } else {
                     $object = $this->service->getObjectConcreteById($id);
                 }
                 if ($profile) {
                     $timeConsumedGetWebservice = round(microtime(true) - $startTs, 3) * 1000;
                 }
                 if ($profile) {
                     $profiling = array();
                     $profiling["get"] = $timeConsumedGet;
                     $profiling["perm"] = $timeConsumedPerm;
                     $profiling["ws"] = $timeConsumedGetWebservice;
                     $profiling["init"] = $this->timeConsumedInit;
                     $result = array("success" => true, "profiling" => $profiling, "data" => $object);
                 } else {
                     $result = array("success" => true, "data" => $object);
                 }
                 $this->encoder->encode($result);
                 return;
             }
         } else {
             if ($this->isDelete()) {
                 $object = Object::getById($id);
                 if ($object) {
                     $this->checkPermission($object, "delete");
                 }
                 $success = $this->service->deleteObject($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"]) {
                         $obj = Object::getById($data["id"]);
                         if ($obj) {
                             $this->checkPermission($obj, "update");
                         }
                         $isUpdate = true;
                         if ($type == "folder") {
                             $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In", $data);
                             $success = $this->service->updateObjectFolder($wsData);
                         } else {
                             $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In", $data);
                             $success = $this->service->updateObjectConcrete($wsData);
                         }
                     } else {
                         if ($type == "folder") {
                             $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In";
                             $method = "createObjectFolder";
                         } else {
                             $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In";
                             $method = "createObjectConcrete";
                         }
                         $wsData = self::fillWebserviceData($class, $data);
                         $obj = new Object();
                         $obj->setId($wsData->parentId);
                         $this->checkPermission($obj, "create");
                         $id = $this->service->{$method}($wsData);
                     }
                     if (!$isUpdate) {
                         $success = $id != null;
                     }
                     $result = array("success" => $success);
                     if ($success && !$isUpdate) {
                         $result["id"] = $id;
                     }
                     $this->encoder->encode($result);
                     return;
                 }
             }
         }
     } catch (\Exception $e) {
         \Logger::error($e);
         $this->encoder->encode(array("success" => false, "msg" => (string) $e));
     }
     throw new \Exception("not implemented");
 }
开发者ID:yonetici,项目名称:pimcore-coreshop-demo,代码行数:101,代码来源:RestController.php

示例2: objectAction


//.........这里部分代码省略.........
             } else {
                 /**
                  * @api {put} /object Create a new object
                  * @apiName Create a new object
                  * @apiGroup Object
                  * @apiSampleRequest off
                  * @apiDescription
                  * Request body: JSON-encoded object data in the same format as returned by get object by id for the data segment but with missing id field or id set to 0
                  *
                  * @apiParam {json} data a new object data
                  * @apiParam {string} apikey your access token
                  * @apiParamExample {json} Request-Example:
                  *     {
                  *         "apikey": "21314njdsfn1342134",
                  *         "data": {
                  *               "id": 61,
                  *               "parentId": 48,
                  *               "key": "test-product-key",
                  *               "className": "product",
                  *               "type": "object",
                  *               "elements": [
                  *                   {
                  *                   "type": "input",
                  *                   "value": "some identyfier",
                  *                   "name": "identyfier",
                  *                   "language": null
                  *                   },
                  *                   {
                  *                   "type": "localizedfields",
                  *                   "value": [
                  *                   {
                  *                   "type": "input",
                  *                   "value": "Test",
                  *                   "name": "name1",
                  *                   "language": "en"
                  *                   },
                  *                   {
                  *                   "type": "input",
                  *                   "value": "1",
                  *                   "name": "name2",
                  *                   "language": "en"
                  *                   },
                  *                   {
                  *                   "type": "input",
                  *                   "value": null,
                  *                   "name": "name1",
                  *                   "language": "de"
                  *                   },
                  *                   {
                  *                   "type": "input",
                  *                   "value": "aaa",
                  *                   "name": "name2",
                  *                   "language": "de"
                  *                   }
                  *                   ],
                  *                   "name": "localizedfields",
                  *                   "language": null
                  *                       }
                  *               ]
                  *           }
                  *     }
                  * @apiSuccess {json} success parameter of the returned data = true
                  * @apiError {json} success parameter of the returned data = false
                  * @apiErrorExample {json} Error-Response:
                  *                  {"success":false, "msg":"exception 'Exception' with message '....'"}
                  * @apiSuccessExample {json} Success-Response:
                  *                    HTTP/1.1 200 OK
                  *                    {
                  *                      "success": true
                  *                    }
                  */
                 if ($type == "folder") {
                     $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Folder\\In";
                     $method = "createObjectFolder";
                 } else {
                     $class = "\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\In";
                     $method = "createObjectConcrete";
                 }
                 $wsData = self::fillWebserviceData($class, $data);
                 $obj = new Object();
                 $obj->setId($wsData->parentId);
                 $this->checkPermission($obj, "create");
                 $id = $this->service->{$method}($wsData);
             }
             if (!$isUpdate) {
                 $success = $id != null;
             }
             $result = ["success" => $success];
             if ($success && !$isUpdate) {
                 $result["id"] = $id;
             }
             $this->encoder->encode($result);
             return;
         }
     } catch (\Exception $e) {
         Logger::error($e);
         $this->encoder->encode(["success" => false, "msg" => (string) $e]);
     }
     throw new \Exception("not implemented");
 }
开发者ID:pimcore,项目名称:pimcore,代码行数:101,代码来源:RestController.php


注:本文中的Pimcore\Model\Object::setId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。