当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveRecord::getPrimaryKey方法代码示例

本文整理汇总了PHP中yii\db\ActiveRecord::getPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::getPrimaryKey方法的具体用法?PHP ActiveRecord::getPrimaryKey怎么用?PHP ActiveRecord::getPrimaryKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\db\ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::getPrimaryKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCreateUpdateResponse

 /**
  * @param ActiveRecord $model
  * @param array $actions Custom actions array in the form of
  * ```php
  * 'name' => function() {
  *
  * }
  * ```
  * @param bool $addDefaultActions If true default actions will be added
  * @return \yii\web\Response
  * @throws BadRequestHttpException
  */
 protected function getCreateUpdateResponse($model, $actions = [], $addDefaultActions = true)
 {
     $defaultActions = [AdminHtml::ACTION_SAVE_AND_STAY => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         return $this->redirect(['update', 'id' => $model->getPrimaryKey()]);
     }, AdminHtml::ACTION_SAVE_AND_CREATE => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         if ($url = Url::previous($this->createUrlParam)) {
             Url::remember(null, $this->createUrlParam);
             return $this->redirect($url);
         }
         return $this->redirect(['create']);
     }, AdminHtml::ACTION_SAVE_AND_LEAVE => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         if ($url = \Yii::$app->request->get('return')) {
             return $this->redirect($url);
         }
         if ($url = Url::previous($this->indexUrlParam)) {
             Url::remember(null, $this->indexUrlParam);
             return $this->redirect($url);
         }
         return $this->redirect(['index']);
     }];
     if ($addDefaultActions) {
         $actions = array_merge($defaultActions, $actions);
     }
     $actionName = \Yii::$app->request->post(AdminHtml::ACTION_BUTTON_NAME, AdminHtml::ACTION_SAVE_AND_LEAVE);
     if (isset($actions[$actionName])) {
         return call_user_func($actions[$actionName]);
     } else {
         throw new BadRequestHttpException('Unknown action: ' . $actionName);
     }
 }
开发者ID:omnilight,项目名称:yz2-admin,代码行数:45,代码来源:CrudControllerTrait.php

示例2: 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

示例3: getUrl

 /**
  * @param $direction string
  * @param $model ActiveRecord
  * @return array
  */
 protected function getUrl($direction, ActiveRecord $model)
 {
     $url = !empty($this->url) ? $this->url : ['order'];
     $url['direction'] = $direction;
     $url['attribute'] = $this->attribute;
     $url['id'] = $model->getPrimaryKey();
     return $url;
 }
开发者ID:Wubbleyou,项目名称:yii2-ordermodel,代码行数:13,代码来源:OrderModelColumn.php

示例4: run

 public function run()
 {
     $buttons = [];
     $translations = $this->model->translations;
     foreach ($translations as $translationModel) {
         /** @var ActiveRecord | TranslatableInterface $translationModel */
         // if ($translationModel->equals($this->model)) continue;
         $lang = $translationModel->language;
         $buttons[$lang] = Html::a($lang, ['update', 'id' => $translationModel->getPrimaryKey()], ['class' => 'btn btn-xs' . ($this->model->language == $lang ? ' btn-primary' : ' btn-default'), 'data-pjax' => '0']);
     }
     $unsupportedLanguages = array_diff(Yii::$app->acceptedLanguages, array_keys($buttons));
     foreach ($unsupportedLanguages as $lang) {
         $buttons[$lang] = Html::a($lang, ['create', 'language' => $lang, 'sourceId' => $this->model->getPrimaryKey()], ['class' => 'btn btn-danger btn-xs', 'data-pjax' => '0']);
     }
     ksort($buttons);
     return implode(' ', $buttons);
 }
开发者ID:gromver,项目名称:yii2-platform-basic,代码行数:17,代码来源:TranslationsBackend.php

示例5: getFilenameFor

 /**
  * @param  ActiveRecord $activeRecord
  * @param               $attribute
  * @param null $extension
  *
  * @return string
  */
 public function getFilenameFor($activeRecord, $attribute, $extension = null)
 {
     $path = Inflector::camel2id((new \ReflectionClass($activeRecord))->getShortName());
     $basename = implode('-', $activeRecord->getPrimaryKey(true)) . '-' . $attribute;
     if ($extension) {
         $basename .= '.' . $extension;
     }
     return $path . DIRECTORY_SEPARATOR . $basename;
 }
开发者ID:voodoo-mobile,项目名称:yii2-upload,代码行数:16,代码来源:Writer.php

示例6: run

 /** Render widget */
 public function run()
 {
     if ($this->apiRoute === null) {
         throw new Exception('$apiRoute must be set.', 500);
     }
     $images = array();
     foreach ($this->behavior->getImages() as $image) {
         $images[] = array('id' => $image->id, 'rank' => $image->rank, 'name' => (string) $image->name, 'description' => (string) $image->description, 'preview' => $image->getUrl('preview'));
     }
     $baseUrl = [$this->apiRoute, 'type' => $this->behavior->type, 'behaviorName' => $this->behaviorName, 'galleryId' => $this->model->getPrimaryKey()];
     $opts = array('hasName' => $this->behavior->hasName ? true : false, 'hasDesc' => $this->behavior->hasDescription ? true : false, 'uploadUrl' => Url::to($baseUrl + ['action' => 'ajaxUpload']), 'deleteUrl' => Url::to($baseUrl + ['action' => 'delete']), 'updateUrl' => Url::to($baseUrl + ['action' => 'changeData']), 'arrangeUrl' => Url::to($baseUrl + ['action' => 'order']), 'nameLabel' => Yii::t('bupy7/gallery/manager/core', 'Name'), 'descriptionLabel' => Yii::t('bupy7/gallery/manager/core', 'Description'), 'photos' => $images);
     $opts = Json::encode($opts);
     $view = $this->getView();
     GalleryManagerAsset::register($view);
     $view->registerJs("\$('#{$this->id}').galleryManager({$opts});");
     $this->options['id'] = $this->id;
     $this->options['class'] = 'gallery-manager';
     return $this->render('manager');
 }
开发者ID:bupy7,项目名称:yii2-gallery-manager,代码行数:20,代码来源:GalleryManager.php

示例7: initDefaults

 /**
  * Initialize widget with default options.
  *
  * @throws \yii\base\InvalidConfigException
  */
 public function initDefaults()
 {
     $this->voteUrl = isset($this->voteUrl) ?: Yii::$app->getUrlManager()->createUrl(['vote/default/vote']);
     $this->targetId = isset($this->targetId) ?: $this->model->getPrimaryKey();
     if (!isset($this->aggregateModel)) {
         $this->aggregateModel = $this->isBehaviorIncluded() ? $this->model->getVoteAggregate($this->entity) : VoteAggregate::findOne(['entity' => $this->getModule()->encodeEntity($this->entity), 'target_id' => $this->targetId]);
     }
     if (!isset($this->userValue)) {
         $this->userValue = $this->isBehaviorIncluded() ? $this->model->getUserValue($this->entity) : null;
     }
 }
开发者ID:hauntd,项目名称:yii2-vote,代码行数:16,代码来源:BaseWidget.php

示例8: insertIntoInternal

 /**
  * Append to operation internal handler
  * @param bool $append
  * @throws Exception
  */
 protected function insertIntoInternal($append)
 {
     $this->checkNode(false);
     $this->owner->setAttribute($this->parentAttribute, $this->node->getPrimaryKey());
     if ($this->sortable !== false) {
         if ($append) {
             $this->owner->moveLast();
         } else {
             $this->owner->moveFirst();
         }
     }
 }
开发者ID:karsel,项目名称:yii2-adjacency-list,代码行数:17,代码来源:AdjacencyListBehavior.php

示例9: run

 /** Render widget */
 public function run()
 {
     if ($this->apiRoute === null) {
         throw new Exception('$apiRoute must be set.', 500);
     }
     $images = array();
     foreach ($this->behavior->getImages($this->sort) as $image) {
         $images[] = array('id' => $image->id, 'rank' => $image->rank, 'preview' => $image->getUrl('preview'));
     }
     $baseUrl = [$this->apiRoute, 'type' => $this->behavior->type, 'behaviorName' => $this->behaviorName, 'galleryId' => $this->model->getPrimaryKey()];
     $opts = array('uploadUrl' => Url::to($baseUrl + ['action' => 'ajaxUpload']), 'deleteUrl' => Url::to($baseUrl + ['action' => 'delete']), 'updateUrl' => Url::to($baseUrl + ['action' => 'changeData']), 'arrangeUrl' => Url::to($baseUrl + ['action' => 'order']), 'photos' => $images, 'prepend' => $this->prepend);
     $opts = Json::encode($opts);
     $view = $this->getView();
     GalleryManagerAsset::register($view);
     $view->registerJs("(function(){\$('#{$this->id}').galleryManager({$opts});})();", \yii\web\View::POS_READY);
     $this->options['id'] = $this->id;
     $this->options['class'] = 'gallery-manager';
     if ($this->view) {
         return $this->render($this->view);
     }
     return $this->render('galleryManager');
 }
开发者ID:dlds,项目名称:yii2-gallery-manager,代码行数:23,代码来源:GalleryManager.php

示例10: getNewTranslation

 /**
  * Loads a specific translation model
  *
  * @param string $language the language to return
  *
  * @return null|\yii\db\ActiveQuery|static
  */
 private function getNewTranslation($language)
 {
     $translation = null;
     /** @var \yii\db\ActiveQuery $relation */
     $relation = $this->owner->getRelation($this->relation);
     /** @var ActiveRecord $class */
     $class = $relation->modelClass;
     //if ($translation === null) {
     $translation = new $class();
     $translation->{key($relation->link)} = $this->owner->getPrimaryKey();
     $translation->{$this->languageAttribute} = $language;
     //}
     return $translation;
 }
开发者ID:maddoger,项目名称:yii2-core,代码行数:21,代码来源:TranslatableBehavior.php

示例11: delete

 /**
  * Deletes this notification
  */
 public function delete(\humhub\modules\user\models\User $user = null)
 {
     $condition = [];
     $condition['class'] = $this->className();
     if ($user !== null) {
         $condition['user_id'] = $user->id;
     }
     if ($this->originator !== null) {
         $condition['originator_user_id'] = $this->originator->id;
     }
     if ($this->source !== null) {
         $condition['source_pk'] = $this->source->getPrimaryKey();
         $condition['source_class'] = $this->source->className();
     }
     Notification::deleteAll($condition);
 }
开发者ID:honestgorillas,项目名称:humhub,代码行数:19,代码来源:BaseNotification.php

示例12: create

 /**
  * Creates an activity
  *
  * @throws \yii\base\Exception
  */
 public function create()
 {
     if ($this->moduleId == "") {
         throw new \yii\base\InvalidConfigException("No moduleId given!");
     }
     if (!$this->source instanceof \yii\db\ActiveRecord) {
         throw new \yii\base\InvalidConfigException("Invalid source object given!");
     }
     $model = new Activity();
     $model->class = $this->className();
     $model->module = $this->moduleId;
     $model->content->visibility = $this->visibility;
     $model->object_model = $this->source->className();
     $model->object_id = $this->source->getPrimaryKey();
     // Automatically determine content container
     if ($this->container == null) {
         if ($this->source instanceof ContentActiveRecord || $this->source instanceof ContentAddonActiveRecord) {
             $this->container = $this->source->content->container;
             // Take visibility from Content/Addon
             $model->content->visibility = $this->source->content->visibility;
         } elseif ($this->source instanceof ContentContainerActiveRecord) {
             $this->container = $this->source;
         } else {
             throw new \yii\base\InvalidConfigException("Could not determine content container for activity!");
         }
     }
     $model->content->container = $this->container;
     // Automatically determine originator - if not set
     if ($this->originator !== null) {
         $model->content->user_id = $this->originator->id;
     } elseif ($this->source instanceof ContentActiveRecord) {
         $model->content->user_id = $this->source->content->user_id;
     } elseif ($this->source instanceof ContentAddonActiveRecord) {
         $model->content->user_id = $this->source->created_by;
     } else {
         throw new \yii\base\InvalidConfigException("Could not determine originator for activity!");
     }
     if (!$model->validate() || !$model->save()) {
         throw new \yii\base\Exception("Could not save activity!" . $model->getErrors());
     }
 }
开发者ID:weison-tech,项目名称:humhub,代码行数:46,代码来源:BaseActivity.php

示例13: insertTo

 /**
  * @param $position
  * @return bool
  * @throws \yii\db\Exception
  */
 public function insertTo($position)
 {
     if ($this->getValue() == $position) {
         return true;
     }
     // 59 -> 56 = 58 57 56
     // 56 -> 59 = 57 58 59
     $start = $this->getValue();
     $end = $position;
     if ($start == null || $start == 0) {
         $this->setInsertSort();
         $this->owner->save();
         return true;
     }
     $direction = $start > $end ? static::DirectionDown : static::DirectionUp;
     $query = $this->getQuery();
     $query->andWhere(['between', $this->attributeName, min($start, $end), max($start, $end)]);
     $query->getSortBehavior()->sort();
     /**
      * @var ISortableActiveRecord[]|ActiveRecord[] $items
      */
     $items = $query->all();
     $transaction = $this->owner->getDb()->beginTransaction();
     try {
         foreach ($items as $index => $item) {
             if ($item->getPrimaryKey() == $this->owner->getPrimaryKey()) {
                 $item->getSortBehavior()->setSort($position);
                 $item->save();
             } else {
                 $item->getSortBehavior()->setSort($item->getSortBehavior()->getValue() + ($direction == static::DirectionDown ? 1 : -1));
                 $item->save();
             }
         }
         /* @TODO сделать фикс позиций, что бы не перескакивало и не было дублей */
         $transaction->commit();
     } catch (\Exception $ex) {
         $transaction->rollBack();
         return false;
     }
     return true;
 }
开发者ID:nanodesu88,项目名称:yii2-activerecord-sort,代码行数:46,代码来源:SortBehavior.php

示例14: saveTranslations

 /**
  * Save related model
  *
  * @param array $translations
  *
  * @since 2.0.0
  * @throws NotFoundHttpException
  */
 private function saveTranslations($translations = [])
 {
     /** @var ActiveRecord $owner */
     /** @var ActiveRecord $translation */
     foreach ($this->availableLanguages as $language) {
         if (!isset($translations[$language])) {
             $translation = new $this->translateClassName();
             $translation->{$this->languageField} = $language;
             $translation->{$this->translateForeignKey} = $this->owner->getPrimaryKey();
         } else {
             $translation = $translations[$language];
         }
         foreach ($this->attributes as $attribute) {
             $value = $this->getTranslateAttribute($attribute, $language);
             if ($value !== null) {
                 $translation->{$attribute} = $value;
             }
         }
         $translation->save();
     }
 }
开发者ID:navatech,项目名称:yii2-multi-language,代码行数:29,代码来源:LanguageBehavior.php

示例15: run

 public function run()
 {
     return ModalIFrame::widget(['modalOptions' => ['header' => Yii::t('gromver.platform', 'Item Versions Manager - "{title}" (ID:{id})', ['title' => $this->model->title, 'id' => $this->model->getPrimaryKey()]), 'size' => Modal::SIZE_LARGE], 'buttonContent' => Html::a('<i class="glyphicon glyphicon-hdd"></i> ' . Yii::t('gromver.platform', 'Versions'), ['/grom/version/default/item', 'item_id' => $this->model->getPrimaryKey(), 'item_class' => $this->model->className()], ['class' => 'btn btn-default btn-sm'])]);
 }
开发者ID:gromver,项目名称:yii2-platform,代码行数:4,代码来源:Versions.php


注:本文中的yii\db\ActiveRecord::getPrimaryKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。