本文整理汇总了PHP中Pimcore\Model\Document::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::setId方法的具体用法?PHP Document::setId怎么用?PHP Document::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Model\Document
的用法示例。
在下文中一共展示了Document::setId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: documentAction
/** end point for document related data.
* - get document by id
* GET http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
* returns json-encoded document data.
* - delete document by id
* DELETE http://[YOUR-DOMAIN]/webservice/rest/document/id/1281?apikey=[API-KEY]
* returns json encoded success value
* - create document
* PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
* body: json-encoded document data in the same format as returned by get document by id
* but with missing id field or id set to 0
* returns json encoded document id
* - update document
* PUT or POST http://[YOUR-DOMAIN]/webservice/rest/document?apikey=[API-KEY]
* body: same as for create document but with object id
* returns json encoded success value
* @throws \Exception
*/
public function documentAction()
{
$id = $this->getParam("id");
$success = false;
try {
if ($this->isGet()) {
$doc = Document::getById($id);
if (!$doc) {
$this->encoder->encode(array("success" => false, "msg" => "Document does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST));
return;
}
$this->checkPermission($doc, "get");
if ($doc) {
$type = $doc->getType();
$getter = "getDocument" . ucfirst($type) . "ById";
if (method_exists($this->service, $getter)) {
$object = $this->service->{$getter}($id);
} else {
// check if the getter is implemented by a plugin
$class = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . ucfirst($type) . "\\Out";
if (Tool::classExists($class)) {
Document\Service::loadAllDocumentFields($doc);
$object = Webservice\Data\Mapper::map($doc, $class, "out");
} else {
throw new \Exception("unknown type");
}
}
}
if (!$object) {
throw new \Exception("could not find document");
}
@$this->encoder->encode(array("success" => true, "data" => $object));
return;
} else {
if ($this->isDelete()) {
$doc = Document::getById($id);
if ($doc) {
$this->checkPermission($doc, "delete");
}
$success = $this->service->deleteDocument($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;
$typeUpper = ucfirst($type);
$className = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . $typeUpper . "\\In";
if ($data["id"]) {
$doc = Document::getById($data["id"]);
if ($doc) {
$this->checkPermission($doc, "update");
}
$isUpdate = true;
$setter = "updateDocument" . $typeUpper;
if (!method_exists($this->service, $setter)) {
throw new \Exception("method does not exist " . $setter);
}
$wsData = self::fillWebserviceData($className, $data);
$success = $this->service->{$setter}($wsData);
} else {
$setter = "createDocument" . $typeUpper;
if (!method_exists($this->service, $setter)) {
throw new \Exception("method does not exist " . $setter);
}
$wsData = self::fillWebserviceData($className, $data);
$doc = new Document();
$doc->setId($wsData->parentId);
$this->checkPermission($doc, "create");
$id = $this->service->{$setter}($wsData);
}
if (!$isUpdate) {
$success = $id != null;
}
if ($success && !$isUpdate) {
$this->encoder->encode(array("success" => $success, "id" => $id));
} else {
$this->encoder->encode(array("success" => $success));
}
return;
//.........这里部分代码省略.........
示例2: documentAction
//.........这里部分代码省略.........
}
@$this->encoder->encode(["success" => true, "data" => $object]);
return;
} elseif ($this->isDelete()) {
/**
* @api {delete} /document Delete document
* @apiName deleteDocument
* @apiGroup Document
* @apiParam {int} id The id of document you delete
* @apiSampleRequest off
* @apiParamExample {json} Request-Example:
* {
* "id": 4711
* "apikey": '2132sdf2321rwefdcvvce22'
* }
* @apiParam {string} apikey your access token
* @apiSuccess {boolean} success Returns true if finished successfully
* @apiSuccessExample {json} Succes-Response:
* HTTP/1.1 200 OK
* {
* "success":true
* }
* @apiError {boolean} success Returns false if failed
* @apiErrorExample {json} Error-Response:
* {"success":false,"msg":"exception 'Exception' with message 'Document with given ID (712131243) does not exist.'"}
*/
$doc = Document::getById($id);
if ($doc) {
$this->checkPermission($doc, "delete");
}
$success = $this->service->deleteDocument($id);
$this->encoder->encode(["success" => $success]);
return;
} elseif ($this->isPost() || $this->isPut()) {
/**
* @api {post} /document Update document
* @apiName updateDocument
* @apiGroup Document
* @apiParam {int} id The id of document you delete
* @apiSampleRequest off
* @apiParamExample {json} Request-Example:
* {
* "id": 4711
* "apikey": '2132sdf2321rwefdcvvce22'
* }
* @apiParam {string} apikey your access token
* @apiSuccess {boolean} success Returns true if finished successfully
* @apiSuccessExample {json} Succes-Response:
* HTTP/1.1 200 OK
* {
* "success":true
* }
* @apiError {boolean} success Returns false if failed
* @apiErrorExample {json} Error-Response:
* {"success":false,"msg":"exception 'Exception' with message 'Document with given ID (712131243) does not exist.'"}
*/
$data = file_get_contents("php://input");
$data = \Zend_Json::decode($data);
$type = $data["type"];
$id = null;
$typeUpper = ucfirst($type);
$className = "\\Pimcore\\Model\\Webservice\\Data\\Document\\" . $typeUpper . "\\In";
if ($data["id"]) {
$doc = Document::getById($data["id"]);
if ($doc) {
$this->checkPermission($doc, "update");
}
$isUpdate = true;
$setter = "updateDocument" . $typeUpper;
if (!method_exists($this->service, $setter)) {
throw new \Exception("method does not exist " . $setter);
}
$wsData = self::fillWebserviceData($className, $data);
$success = $this->service->{$setter}($wsData);
} else {
$setter = "createDocument" . $typeUpper;
if (!method_exists($this->service, $setter)) {
throw new \Exception("method does not exist " . $setter);
}
$wsData = self::fillWebserviceData($className, $data);
$doc = new Document();
$doc->setId($wsData->parentId);
$this->checkPermission($doc, "create");
$id = $this->service->{$setter}($wsData);
}
if (!$isUpdate) {
$success = $id != null;
}
if ($success && !$isUpdate) {
$this->encoder->encode(["success" => $success, "id" => $id]);
} else {
$this->encoder->encode(["success" => $success]);
}
return;
}
} catch (\Exception $e) {
$this->encoder->encode(["success" => false, "msg" => (string) $e]);
}
$this->encoder->encode(["success" => false]);
}