本文整理汇总了PHP中DatabaseObject::getDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseObject::getDatabase方法的具体用法?PHP DatabaseObject::getDatabase怎么用?PHP DatabaseObject::getDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseObject
的用法示例。
在下文中一共展示了DatabaseObject::getDatabase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadFor
public static function loadFor($linkClass, DatabaseObject $for)
{
assert(class_exists($linkClass));
assert(is_subclass_of($linkClass, __CLASS__));
if (!isset($for->id)) {
throw new InvalidArgumentException('unsaved DatabaseObject');
}
$database = $for->getDatabase();
$meta = DatabaseObjectLinkMeta::forClass($linkClass, $for->_db);
$data = array();
if (is_a($for, $meta->getFromClass())) {
$sql = $meta->getSQL('link_load_from');
$data['from'] = $for;
$other = 'to';
$otherClass = $meta->getToClass();
} elseif (is_a($for, $meta->getToClass())) {
$sql = $meta->getSQL('link_load_to');
$data['to'] = $for;
$other = 'from';
$otherClass = $meta->getFromClass();
} else {
throw new InvalidArgumentException('invalid DatabaseObject, expecting a ' . $meta->getFromClass() . 'or a ' . $meta->getToClass());
}
$otherId = null;
$list = $database->execute($sql, $for->id);
$list->bindColumn(1, $otherId);
$i = 1;
foreach (array_merge($meta->getAdditionalKey(), $meta->getAutomaticColumns()) as $column) {
$data[$column] = null;
$list->bindColumn(++$i, $data[$column]);
}
$r = array();
$call = array($linkClass, 'factory');
while ($list->fetch()) {
$data[$other] = DatabaseObject::load($otherClass, $otherId);
array_push($r, call_user_func($call, $data));
}
return $r;
}