本文整理汇总了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();
}