本文整理汇总了PHP中unknown::getTableName方法的典型用法代码示例。如果您正苦于以下问题:PHP unknown::getTableName方法的具体用法?PHP unknown::getTableName怎么用?PHP unknown::getTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unknown
的用法示例。
在下文中一共展示了unknown::getTableName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTableName
/**
* get the table name by passing this along to the underlying model
*/
public function getTableName($type = 'plural')
{
$property = $type . 'TableName';
if ($this->{$property} == null) {
$this->model = $this->getModel();
$this->{$property} = $this->model->getTableName($type);
}
return $this->{$property};
}
示例2: normalizeRelatedRecords
/**
* Normalize the related records so they can be added into the response object
*
* @param unknown $baseRecord
* @param unknown $relatedRecords
* @param unknown $relation
* @return boolean
*/
protected function normalizeRelatedRecords($baseRecord, $relatedRecords, $relation)
{
$refType = $relation->getType();
$refModelNameSpace = $relation->getReferencedModel();
// store a copy of all related record (PKIDs)
// this must be attached w/ the parent records for joining purposes
$relatedRecordIds = null;
$refModel = new $refModelNameSpace();
$primaryKeyName = $refModel->getPrimaryKeyName();
// save the PKID for each record returned
if (count($relatedRecords) > 0) {
// 1 = hasOne 0 = belongsTo 2 = hasMany
switch ($refType) {
// process hasOne records as well
case 1:
// do nothin w/ hasOne since these are auto merged into the main record
break;
case 0:
// this doesn't seem right, why are they occasionally showing up inside an array?
if (isset($relatedRecords[$primaryKeyName])) {
$relatedRecordIds = $relatedRecords[$primaryKeyName];
// wrap in array so we can store multiple hasOnes from many different main records
$relatedRecords = array($relatedRecords);
} else {
$relatedRecordIds = $relatedRecords[0][$primaryKeyName];
}
break;
default:
$relatedRecordIds = array();
foreach ($relatedRecords as $rec) {
$relatedRecordIds[] = $rec[$primaryKeyName];
}
break;
}
} else {
$relatedRecordIds = null;
}
// we map table names to end point resource names and vice versa
// regardless of relationship, the related records are returned as part of the end point resource name
$this->updateRestResponse($relation->getTableName(), $relatedRecords);
// add related record ids to the baseArray
// this is how JSON API suggests that you related resources
// will save nothing, a single value or an array
// does this only run when working with hasMany?
// belongsTo and hasOne are already in place, yes?
if ($relatedRecordIds !== null) {
if ($refType == 2 || $refType == 4) {
$suffix = '_ids';
// populate the linked property or merge in additional records
// attempt to store the name similar to the table name
$name = $relation->getTableName('singular');
$this->baseRecord[$name . $suffix] = $relatedRecordIds;
}
}
return true;
}