本文整理汇总了PHP中Phalcon\Mvc\Model::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::toArray方法的具体用法?PHP Model::toArray怎么用?PHP Model::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Model
的用法示例。
在下文中一共展示了Model::toArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save($data = null, $whiteList = null)
{
$response = array();
if (parent::save($data, $whiteList) == false) {
foreach (parent::getMessages() as $message) {
$response['errors'][] = (string) $message;
}
} else {
foreach (parent::toArray() as $key => $value) {
$response[$key] = $value;
}
$response['msg'] = 'ok';
}
return $response;
}
示例2: toArray
public function toArray($columns = null)
{
if (is_null($columns) && is_array($this->visible)) {
// Only show the visible columns
$columns = $this->visible;
}
$attributes = parent::toArray($columns);
if (is_null($columns) && is_array($this->hidden) && count($attributes)) {
// Only show columns which have not been hidden
foreach ($attributes as $key => $value) {
if (in_array($key, $this->hidden)) {
unset($attributes[$key]);
}
}
}
return $attributes;
}
示例3: onRemoveFailed
protected function onRemoveFailed(Model $item)
{
throw new Exception(ErrorCodes::DATA_FAILED, 'Unable to remove item', ['messages' => $this->_getMessages($item->getMessages()), 'item' => $item->toArray()]);
}
示例4: getDiff
/**
* @return \Diff\DiffOp\DiffOp[]
*/
protected function getDiff()
{
$oldModel = $this->oldModel ? $this->oldModel->toArray() : array();
$newModel = $this->newModel ? $this->newModel->toArray() : array();
return $this->differ->doDiff($oldModel, $newModel);
}
示例5: respondWithModel
/**
* Respond with a single model, pass function name
*/
protected function respondWithModel(Model $model, $functionName = null)
{
// Return a partial response
if ($functionName && isset($this->partialFields)) {
// Validate that there are fields set for this method
if (!isset($this->allowedPartialFields[$functionName])) {
throw new Exception('Partial fields not specified for ' . $functionName);
}
// Determines if fields is a strict subset of allowed fields
if (array_diff($this->partialFields, $this->allowedPartialFields[$functionName])) {
// todo rework exception
throw new HTTPException("The fields you asked for cannot be returned.", 401, array('dev' => 'You requested to return fields that are not available to be returned in partial responses.', 'internalCode' => 'P1000', 'more' => ''));
}
$this->response->data = $model->toArray($this->partialFields);
} else {
$this->response->data = (object) $model->toArray();
$this->response->getMeta()->count = count($this->response->data);
}
// Expand related models
if ($this->isExpand) {
// todo allow for parsed related fields, model.field
foreach ($this->expandFields as $modelField) {
//$this->response[$modelField] = $model->getRelated($modelField)->toArray();
}
}
return $this->response;
}