本文整理汇总了PHP中AbstractModel::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::toArray方法的具体用法?PHP AbstractModel::toArray怎么用?PHP AbstractModel::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
/**
* @return array
*/
public function toArray()
{
$return = parent::toArray();
if ($this->intervention !== null) {
if (!$this->intervention instanceof Intervention) {
throw new \Bixev\InterventionSdk\Exception('invalid intervention instance (must be instanceof \\Bixev\\InterventionSdk\\Intervention');
}
$return['intervention'] = $this->intervention->toArray();
}
if ($this->custom_fields !== null) {
if (!$this->custom_fields instanceof InterventionReportCustomFields) {
throw new \Bixev\InterventionSdk\Exception('invalid custom_fields instance (must be instanceof \\Bixev\\InterventionSdk\\InterventionReportCustomFields');
}
$return['custom_fields'] = $this->custom_fields->toArray();
}
return $return;
}
示例2: processSave
private function processSave(AbstractModel $model)
{
$model->callback('onSaveBegin');
$model_props = $model->toArray();
$table_name = $model->getTableName();
$keys = array();
$values = array();
$primaryKey = $model->getPrimaryKey();
foreach ($model_props as $key => $value) {
if ($key !== $primaryKey && $key !== 'childs') {
if (is_object($value) || is_array($value)) {
continue;
}
$keys[] = '`' . $key . '`';
if ($value == 'CURRENT_TIMESTAMP' || $value == 'NOW()') {
$values[] = "{$value}";
} else {
$values[] = "'{$value}'";
}
}
}
$columns = implode(', ', $keys);
$vals = implode(', ', $values);
$query = "INSERT INTO `{$table_name}`({$columns}) VALUES({$vals})";
$this->dump($query);
$result = $this->db->exec($query);
if ($result) {
$id = $this->db->getLastId();
$model->setId($id);
$model->callback('onSaveEnd');
return true;
} else {
return false;
}
}
示例3: toArray
/**
* Takes object and transforms it to array
* @return [type] [description]
*/
public function toArray()
{
$data = parent::toArray();
if (isset($data['address'])) {
$data['address'] = $data['address']->toArray();
}
if (isset($data['candidates'])) {
$zipcodeCandidates = array();
foreach ($data['candidates'] as $zipcode) {
$zipcodeCandidates[] = $zipcode->toArray();
}
$data['candidates'] = $zipcodeCandidates;
}
return $data;
}