本文整理匯總了PHP中xPDOObject::fromArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP xPDOObject::fromArray方法的具體用法?PHP xPDOObject::fromArray怎麽用?PHP xPDOObject::fromArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xPDOObject
的用法示例。
在下文中一共展示了xPDOObject::fromArray方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: delete
/**
* Handle DELETE requests
* @return array
*/
public function delete()
{
$id = $this->getProperty($this->primaryKeyField, false);
if (empty($id)) {
return $this->failure($this->modx->lexicon('rest.err_field_ns', array('field' => $this->primaryKeyField)));
}
$c = $this->getPrimaryKeyCriteria($id);
$this->object = $this->modx->getObject($this->classKey, $c);
if (empty($this->object)) {
return $this->failure($this->modx->lexicon('rest.err_obj_nf', array('class_key' => $this->classKey)));
}
if (!empty($this->deleteRequiredFields)) {
if (!$this->checkRequiredFields($this->deleteRequiredFields)) {
return $this->failure();
}
}
$this->object->fromArray($this->getProperties());
$beforeDelete = $this->beforeDelete();
if ($beforeDelete !== true) {
return $this->failure($beforeDelete === false ? $this->errorMessage : $beforeDelete);
}
if (!$this->object->{$this->deleteMethod}()) {
$this->setObjectErrors();
return $this->failure($this->modx->lexicon('rest.err_class_remove', array('class_key' => $this->classKey)));
}
$objectArray = $this->object->toArray();
$this->afterDelete($objectArray);
return $this->success('', $objectArray);
}
示例2: process
/**
* {@inheritDoc}
* @return mixed
*/
public function process()
{
/* Run the beforeSet method before setting the fields, and allow stoppage */
$canSave = $this->beforeSet();
if ($canSave !== true) {
return $this->failure($canSave);
}
$this->newObject->fromArray($this->object->toArray());
$name = $this->getNewName();
$this->setNewName($name);
if ($this->alreadyExists($name)) {
$this->addFieldError($this->nameField, $this->modx->lexicon($this->objectType . '_err_ae', array('name' => $name)));
}
$canSave = $this->beforeSave();
if ($canSave !== true) {
return $this->failure($canSave);
}
/* save new chunk */
if ($this->newObject->save() === false) {
$this->modx->error->checkValidation($this->newObject);
return $this->failure($this->modx->lexicon($this->objectType . '_err_duplicate'));
}
$this->afterSave();
$this->logManagerAction();
return $this->cleanup();
}