本文整理匯總了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 . "'");
}
}