當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CModel::primaryKey方法代碼示例

本文整理匯總了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;
 }
開發者ID:dev-lav,項目名稱:htdocs,代碼行數:30,代碼來源:MultiModelForm.php

示例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;
 }
開發者ID:MGGROUP,項目名稱:SAMDEPURACION,代碼行數:40,代碼來源:MultiModelForm.php


注:本文中的CModel::primaryKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。