当前位置: 首页>>代码示例>>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;未经允许,请勿转载。