本文整理汇总了PHP中DBObject::getIdFieldName方法的典型用法代码示例。如果您正苦于以下问题:PHP DBObject::getIdFieldName方法的具体用法?PHP DBObject::getIdFieldName怎么用?PHP DBObject::getIdFieldName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBObject
的用法示例。
在下文中一共展示了DBObject::getIdFieldName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* Magic methods for readable method names.
*
* @param string $methodName Name of the method.
* @param array $methodParams Method parameters.
*
* @return mixed
* @throws DBSelectorException
*/
public function __call($methodName, $methodParams)
{
/*
* Selects DBObject record by some field value.
*
* @param <mixed> Value of the field
*
* @return DBObject
*/
if (preg_match("#^select([[:alpha:]]+)By([[:alpha:]]+)#", $methodName, $matches)) {
if (empty($methodParams[0])) {
return null;
}
$this->validateClassName($matches[1]);
$fieldName = substr(strtolower(preg_replace("#([A-Z]{1})#", "_\$1", $matches[2])), 1);
$fieldValue = $methodParams[0];
if ($fieldName == "id") {
return $this->selectDBObjectById($fieldValue);
}
return $this->selectDBObjectByField($fieldName, $fieldValue);
} elseif (preg_match("#^selectAll([A-Z]{1}[[:alpha:]]+)s#", $methodName, $matches)) {
$this->validateClassName(preg_replace("#ie\$#", "y", $matches[1]));
$this->order = "`" . $this->dbObject->getIdFieldName() . "` DESC";
if (isset($methodParams[0])) {
$this->order = (string) $methodParams[0];
}
$dbObjects = $this->selectDBObjects();
$this->reset();
return $dbObjects;
} elseif (preg_match("#^select([[:alpha:]]+)s#", $methodName, $matches)) {
$this->validateClassName(preg_replace("#ie\$#", "y", $matches[1]));
return $this->selectDBObjects();
} elseif (preg_match("#^select([[:alpha:]]+)#", $methodName, $matches)) {
$this->validateClassName($matches[1]);
return $this->selectDBObject();
}
/*
* Try to call parent method __call() with same params by default
*/
$method = substr($methodName, 0, 3);
$fieldName = $this->getFieldName(substr($methodName, 3));
switch ($method) {
case "set":
$fieldValue = $methodParams[0];
return $this->setFieldValue($fieldName, $fieldValue);
case "get":
return $this->getFieldValue($fieldName);
default:
throw new DBSelectorException("No method with name '" . $methodName . "'");
}
}