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


PHP ActiveRecord::primaryKey方法代碼示例

本文整理匯總了PHP中yii\db\ActiveRecord::primaryKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveRecord::primaryKey方法的具體用法?PHP ActiveRecord::primaryKey怎麽用?PHP ActiveRecord::primaryKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::primaryKey方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadExisting

 protected function loadExisting()
 {
     $pk = [];
     foreach ($this->_attributes as $attribute) {
         if (in_array($attribute->standardAttribute->name, $this->_instance->primaryKey())) {
             $pk[$attribute->standardAttribute->name] = $attribute->value;
         }
     }
     if (!$pk) {
         return;
     }
     if (count($pk) == 1 && !reset($pk)) {
         return;
     }
     foreach ($pk as $value) {
         if (!$value) {
             throw new RowException($this->row, 'For updated model all primary key attributes must be specified.');
         }
     }
     /* @var $modelClass \yii\db\ActiveRecord */
     $modelClass = $this->_standardModel->className;
     $model = $modelClass::findOne($pk);
     if (!$model) {
         throw new RowException($this->row, 'Model for update not found.');
     }
     $this->_instance = $model;
 }
開發者ID:Bladefidz,項目名稱:ocfa_yii,代碼行數:27,代碼來源:Model.php

示例2: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     if (!$owner instanceof ActiveRecord) {
         throw new InvalidConfigException('Owner of this behavior must be extending ActiveRecord model.');
     }
     parent::attach($owner);
     $this->ownerPrimaryKey = $this->owner->primaryKey()[0];
     if (!isset($this->translationModelName, $this->translationOwnerField, $this->languageField)) {
         throw new InvalidConfigException('Please specify contentModelName and contentOwnerKey in the ' . get_class($this->owner) . ' configuration');
     }
     $this->owner->getValidators();
 }
開發者ID:gbksoft,項目名稱:yii2-multilingual,代碼行數:15,代碼來源:Multilingual.php

示例3: run

 /**
  * @param integer $type
  * @param \yii\db\ActiveRecord $object
  */
 public function run($type, $object)
 {
     $pkey = $object->primaryKey();
     $pkey = $pkey[0];
     $data = ['table' => $object->tableName(true), 'model_id' => $object->getPrimaryKey(), 'type' => $type, 'date' => date('Y-m-d H:i:s', time())];
     switch ($type) {
         case self::EVT_INSERT:
             $data['field_name'] = $pkey;
             $this->saveField($data);
             break;
         case self::EVT_UPDATE:
             foreach ($this->updatedFields as $updatedFieldKey => $updatedFieldValue) {
                 $data['field_name'] = $updatedFieldKey;
                 $data['old_value'] = $updatedFieldValue;
                 $data['new_value'] = $object->{$updatedFieldKey};
                 $this->saveField($data);
             }
             break;
         case self::EVT_DELETE:
             $data['field_name'] = $pkey;
             $this->saveField($data);
             break;
         case self::EVT_UPDATE_PK:
             $data['field_name'] = $pkey;
             $data['old_value'] = $object->getOldPrimaryKey();
             $data['new_value'] = $object->{$pkey};
             $this->saveField($data);
             break;
     }
 }
開發者ID:cubiclab,項目名稱:project-cube,代碼行數:34,代碼來源:ChangedocManager.php

示例4: primaryKey

 public static function primaryKey()
 {
     $class = get_called_class();
     if (!isset(self::$primaryKeyCache[$class])) {
         self::$primaryKeyCache[$class] = parent::primaryKey();
     }
     return self::$primaryKeyCache[$class];
 }
開發者ID:laszlovl,項目名稱:yii2-staticactiverecord,代碼行數:8,代碼來源:ActiveRecord.php

示例5: getCacheKey

 /**
  * Returns the cache key.
  * @return mixed the cache key
  */
 protected function getCacheKey()
 {
     $owner = 0;
     if ($this->owner !== null) {
         $pks = $this->owner->primaryKey();
         $owner = $this->owner->{$pks}[0];
     }
     return [__CLASS__, $this->code, $this->layout, $owner];
 }
開發者ID:manyoubaby123,項目名稱:imshop,代碼行數:13,代碼來源:WidgetArea.php

示例6: attach

 /**
  * @inheritdoc
  * @param ActiveRecord $owner
  */
 public function attach($owner)
 {
     $this->attribute = (array) $this->attribute;
     $primaryKey = $owner->primaryKey();
     $primaryKey = is_array($primaryKey) ? array_shift($primaryKey) : $primaryKey;
     if (in_array($primaryKey, $this->attribute, true) && $owner->getIsNewRecord()) {
         $this->attributes[ActiveRecord::EVENT_AFTER_INSERT] = $this->slugAttribute;
     }
     parent::attach($owner);
 }
開發者ID:zelenin,項目名稱:yii2-slug-behavior,代碼行數:14,代碼來源:Slug.php

示例7: renderDataCellContent

 /**
  * 
  * @param ActiveRecord $model
  * @param type $key
  * @param type $index
  * @return type
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     $result = Html::tag('span', $index + 1, ['class' => 'serial-column']);
     if ($model instanceof ActiveRecord && ($primaryKeys = $model->primaryKey()) != []) {
         foreach ($primaryKeys as $primary) {
             $result .= ' ' . Html::activeHiddenInput($model, "[{$index}]{$primary}");
         }
     }
     return $result;
 }
開發者ID:sangkilsoft,項目名稱:sangkilbiz-3,代碼行數:17,代碼來源:SerialColumn.php

示例8: attach

 /**
  * @param ActiveRecord $owner
  * @throws Exception
  */
 public function attach($owner)
 {
     if ($this->itemAttribute === null) {
         $primaryKey = $owner->primaryKey();
         if (!isset($primaryKey[0])) {
             throw new Exception('"' . $owner->className() . '" must have a primary key.');
         }
         $this->itemAttribute = $primaryKey[0];
         $this->primaryKeyMode = true;
     }
     return parent::attach($owner);
 }
開發者ID:arogachev,項目名稱:yii2-materialized-path,代碼行數:16,代碼來源:MaterializedPathBehavior.php

示例9: asJson

 /**
  * Returns a models primary-key in json format. This works also with
  * composite primary-keys
  *
  * @param \yii\db\ActiveRecord $model the model instance
  * @return string the models pk in json-format
  * @throws \yii\base\InvalidParamException if the model is not of type ActiveRecord
  * @throws \yii\base\InvalidConfigException if the models pk is empty or invalid
  */
 public static function asJson($model)
 {
     //check if the model is valid
     if (!$model instanceof \yii\db\ActiveRecord) {
         throw new InvalidParamException(Yii::t('app', 'The model must be of type ActiveRecord'));
     }
     //fetch the models pk
     $pk = $model->primaryKey();
     //assert that a valid pk was received
     if ($pk === null || !is_array($pk) || count($pk) == 0) {
         $msg = Yii::t('app', 'Invalid primary key definition: please provide a pk-definition for table {table}', ['table' => $model->tableName()]);
         throw new InvalidConfigException($msg);
     }
     //create final array and return it
     $arrPk = [];
     foreach ($pk as $pkCol) {
         $arrPk[$pkCol] = $model->{$pkCol};
     }
     return Json::encode($arrPk);
 }
開發者ID:highestgoodlikewater,項目名稱:yii2-toolbox,代碼行數:29,代碼來源:PrimaryKey.php

示例10: getSeo

 public function getSeo()
 {
     return $this->owner->hasOne(SeoText::className(), ['item_id' => $this->owner->primaryKey()[0]])->where(['class' => $this->owner->className()]);
 }
開發者ID:nanodesu88,項目名稱:easyii,代碼行數:4,代碼來源:SeoBehavior.php

示例11: isDeletedModel

 /**
  * Check if model was deleted (not found in new models).
  *
  * @param ActiveRecord $model
  * @param $attribute
  *
  * @return bool
  */
 protected function isDeletedModel($model, $attribute)
 {
     $modelAttributes = $model->attributes;
     unset($modelAttributes[$model->primaryKey()[0]]);
     foreach ($this->relationalData[$attribute]['newModels'] as $newModel) {
         /** @var ActiveRecord $newModel */
         $newModelAttributes = $newModel->attributes;
         unset($newModelAttributes[$newModel->primaryKey()[0]]);
         if ($newModelAttributes == $modelAttributes) {
             return false;
         }
     }
     return true;
 }
開發者ID:notamedia,項目名稱:yii2-relation,代碼行數:22,代碼來源:RelationBehavior.php

示例12: _getPrimaryKeyName

 /**
  * Retrieves primary key name
  */
 private function _getPrimaryKeyName(\yii\db\ActiveRecord $model, $composite = false)
 {
     $primaryKey = $model->primaryKey();
     if (!$composite && count($primaryKey) > 1) {
         throw new Exception('Model has composit key which is not allowed. Relations cannot be established');
     }
     return array_shift($primaryKey);
 }
開發者ID:dlds,項目名稱:yii2-rels,代碼行數:11,代碼來源:Interpreter.php


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