本文整理汇总了PHP中CModel::primaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP CModel::primaryKey方法的具体用法?PHP CModel::primaryKey怎么用?PHP CModel::primaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CModel
的用法示例。
在下文中一共展示了CModel::primaryKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPrimaryKey
/**
* Get the primary key as array (key => value)
*
* @param CModel $model
* @return array
*/
public function getPrimaryKey($model)
{
$result = array();
if ($model instanceof CActiveRecord) {
$pkValue = $model->primaryKey;
if (!empty($pkValue)) {
$pkName = $model->primaryKey();
if (empty($pkName)) {
$pkName = $model->tableSchema->primaryKey;
}
$result = is_array($pkValue) ? $pkValue : array($pkName => $pkValue);
}
} else {
// when working with EMongoDocument
if (method_exists($model, 'primaryKey')) {
$pkName = $model->primaryKey();
$pkValue = $model->{$pkName};
if (empty($pkValue)) {
$result = array($pkName => $pkValue);
}
}
}
return $result;
}
示例2: getPrimaryKey
/**
* Get the primary key as array (key => value).
* A pk is needed to determine which records to delete.
* If no pk is available it works too, but the deleteditems on validate is always empty and each record isnew.
* Detect the pk from CActiveRecord and EMongoDocument.
* If working with formmodels a custom callbackMethod mmfPrimaryKey of the model will be called if defined.
*
* @param CModel $model
* @return array
*/
public function getPrimaryKey($model)
{
$result = array();
if ($model instanceof CActiveRecord) {
$pkValue = $model->primaryKey;
if (!empty($pkValue)) {
$pkName = $model->primaryKey();
if (empty($pkName)) {
$pkName = $model->tableSchema->primaryKey;
}
$result = is_array($pkValue) ? $pkValue : array($pkName => $pkValue);
}
} elseif (method_exists($model, 'primaryKey')) {
$pkName = $model->primaryKey();
if (is_array($pkName)) {
$result = array();
foreach ($pkName as $pkN) {
$result[$pkN] = $model->{$pkN};
}
} else {
$pkValue = $model->{$pkName};
if (empty($pkValue)) {
$result = array($pkName => $pkValue);
}
}
} elseif (method_exists($model, 'mmfPrimaryKey')) {
$result = $model->mmfPrimaryKey();
}
return $result;
}