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


PHP ActiveRecord::getDb方法代码示例

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


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

示例1: beginTransaction

 protected function beginTransaction()
 {
     $db = $this->owner->getDb();
     if ($db->getTransaction() === null) {
         $this->transaction = $db->beginTransaction();
     }
 }
开发者ID:stee1cat,项目名称:yii2-file-attachment,代码行数:7,代码来源:FileBehavior.php

示例2: getDb

 /**
  * @inheritdoc
  */
 public static function getDb()
 {
     if (Configs::db() !== null) {
         return Configs::db();
     } else {
         return parent::getDb();
     }
 }
开发者ID:Backflag,项目名称:xlzx,代码行数:11,代码来源:Menu.php

示例3: getDb

 /**
  * @inheritdoc
  */
 public static function getDb()
 {
     if (Configs::instance()->db !== null) {
         return Configs::instance()->db;
     } else {
         return parent::getDb();
     }
 }
开发者ID:luoche,项目名称:iisns,代码行数:11,代码来源:Menu.php

示例4: save

 public function save($runValidation = true, $attributes = null)
 {
     if ($runValidation && !$this->validate($attributes)) {
         Yii::info('Dynamic model data were not save due to validation error.', __METHOD__);
         return false;
     }
     $db = $this->entityModel->getDb();
     $transaction = $db->beginTransaction();
     try {
         foreach ($this->handlers as $handler) {
             $handler->valueHandler->save();
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         throw $e;
     }
 }
开发者ID:sunfun,项目名称:yii2-eav,代码行数:18,代码来源:DynamicModel.php

示例5: getDb

 /**
  * @return \yii\db\Connection the database connection used by this AR class.
  */
 public static function getDb()
 {
     if (isset(Yii::$app->params['audittrail.db'])) {
         return Yii::$app->get(Yii::$app->params['audittrail.db']);
     } else {
         return parent::getDb();
     }
     // return Yii::$app->get('dbUser');
 }
开发者ID:sammaye,项目名称:yii2-audittrail,代码行数:12,代码来源:AuditTrail.php

示例6: add

 public static function add($tags, $blog_id)
 {
     $data = [];
     if (Tags::validateTags($tags)) {
         $tags = explode(',', $tags);
     }
     foreach ($tags as $tag) {
         array_push($data, ['name' => $tag, 'blog_id' => $blog_id]);
     }
     parent::getDb()->createCommand()->batchInsert(self::tableName(), ['name', 'blog_id'], $data)->execute();
 }
开发者ID:Crocodile26,项目名称:php-1,代码行数:11,代码来源:Tags.php

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

示例8: deleteAll

 /**
  * Delete all SEO data for ActiveRecord
  * @param ActiveRecord $owner
  */
 public static function deleteAll(ActiveRecord $owner)
 {
     $owner->getDb()->createCommand()->delete(self::tableName($owner), ['model_id' => $owner->getPrimaryKey()])->execute();
 }
开发者ID:inblank,项目名称:yii2-seobility,代码行数:8,代码来源:Seo.php

示例9: aggregate

 /**
  * Convert aggregate query from Kendo UI to DB aggregate functions
  *
  * @param array $aggregates usually values of $_POST['aggregates']
  * @param ActiveRecord $model model for generation aggregate functions
  * @return array aggregate functions for Query::select()
  */
 public static function aggregate($aggregates, ActiveRecord $model)
 {
     if (!$aggregates || !is_array($aggregates)) {
         return [];
     }
     $db = $model->getDb();
     $attributes = $model->attributes();
     $aggregateFunctions = static::AGGREGATE_FUNCTIONS;
     $functions = [];
     foreach ($aggregates as $aggregate) {
         if (!empty($aggregate['aggregate']) && isset($aggregateFunctions[$aggregate['aggregate']]) && !empty($aggregate['field']) && in_array($aggregate['field'], $attributes)) {
             $funcName = $aggregateFunctions[$aggregate['aggregate']];
             $functions[] = $funcName . '(' . $db->quoteColumnName($aggregate['field']) . ') ' . ' AS ' . $db->quoteColumnName($aggregate['aggregate'] . '_' . $aggregate['field']);
         }
     }
     return $functions;
 }
开发者ID:tigrov,项目名称:yii2-kendoui,代码行数:24,代码来源:ParamConverter.php

示例10: unlink

 /**
  * Removed
  *
  * @param mixed $id the id of the class to remove from link table
  */
 protected function unlink($id)
 {
     ActiveRecord::getDb()->createCommand()->delete($this->ownerLinkTable, [$this->ownerLinkTableAttribute => $id])->execute();
 }
开发者ID:2amigos,项目名称:yii2-file-upload-widget,代码行数:9,代码来源:FileDeleteAction.php

示例11: getTranslation

 /**
  * Relation to model translation
  *
  * @param $locale
  * @return ActiveQuery
  */
 public function getTranslation($locale = null)
 {
     $locale = $locale ?: Yii::$app->language;
     return $this->owner->hasOne($this->translationModelName, [$this->translationOwnerField => $this->ownerPrimaryKey])->from(['content' => call_user_func([$this->translationModelName, 'tableName'])])->innerJoin(['lang' => Language::tableName()])->where('lang.locale = :locale', [':locale' => $locale])->andWhere('content.' . $this->owner->getDb()->quoteColumnName($this->languageField) . ' = lang.id');
 }
开发者ID:gbksoft,项目名称:yii2-multilingual,代码行数:11,代码来源:Multilingual.php

示例12: link

 /**
  * Links uploaded file to its owner.
  *
  * @param mixed $ownerId
  * @param mixed $id
  */
 protected function link($ownerId, $id)
 {
     ActiveRecord::getDb()->createCommand()->insert($this->ownerLinkTable, [$this->ownerLinkTableAttribute => $ownerId, $this->ownerLinkTableAttribute => $id])->execute();
 }
开发者ID:2amigos,项目名称:yii2-file-upload-widget,代码行数:10,代码来源:FileUploadAction.php

示例13: saveSettingsModel

 /**
  * Save model of settings
  * @param ActiveRecord $model Model to save
  * @param array $requestParams Request parameters
  * @return bool
  */
 protected function saveSettingsModel(ActiveRecord $model, array $requestParams)
 {
     $success = false;
     $transaction = $model->getDb()->beginTransaction();
     try {
         $model->load($requestParams);
         if ($model->save()) {
             $transaction->commit();
             Yii::$app->interfaceSettings->refreshUserInterfaceSettings($model->user_id, $model->interface_id);
             $success = true;
         } else {
             throw new Exception();
         }
     } catch (Exception $e) {
         if ($transaction->isActive) {
             $transaction->rollBack();
         }
     }
     // trigger an event
     $this->trigger(self::EVENT_SAVE_SETTING, new ExtraDataEvent(['extraData' => ['model' => $model, 'success' => $success]]));
     return $success;
 }
开发者ID:kalibao,项目名称:magesko,代码行数:28,代码来源:Controller.php

示例14: addDirtyModel

 /**
  * @param \yii\db\ActiveRecord $model
  */
 public function addDirtyModel($model)
 {
     // --- debug - start ------------------------------------------------------
     // make sure there's always only one instance referencing a DB record
     $dsn = $model->getDb()->dsn;
     $table = $model->tableName();
     $pk = $model->getPrimaryKey();
     $modelId = "{$dsn}:{$table}:{$pk}";
     if (array_key_exists($modelId, $this->_dirtyModelsInfo)) {
         $storedModel = $this->_dirtyModelsInfo[$modelId];
         if ($storedModel !== $model) {
             throw new \yii\base\NotSupportedException("Can't handle two instances for tabel '{$table}', id '{$pk}' (dsn '{$dsn}').");
         }
     }
     $this->_dirtyModelsInfo[$modelId] = $model;
     // --- debug - end --------------------------------------------------------
     $this->_dirtyModels->attach($model);
 }
开发者ID:iw-reload,项目名称:iw,代码行数:21,代码来源:TaskComponent.php

示例15: init

 /**
  * @overriding
  * @see \yii\base\Object::init()
  */
 public function init()
 {
     parent::init();
     try {
         //Initialize template model of the mail AR.
         $this->_templateModel = Yii::createObject($this->modelClass);
         $this->_db = $this->_templateModel->getDb();
         if ($this->sentByBehavior) {
             $this->sentByBehavior = Yii::createObject($this->sentByBehavior);
         }
     } catch (\ReflectionException $refE) {
         $route = explode('/', Yii::$app->getRequest()->resolve()[0]);
         if (isset(Yii::$app->coreCommands()[$route[0]]) || empty($route[0])) {
             return;
         }
         $action = isset($route[1]) ? $route[1] : '';
         if (!$this->installerMode) {
             $err = "Model class <{$this->modelClass}> not found." . PHP_EOL;
             $err .= "Please install the module first before using it.";
             $err .= "(Instruction in QuickStart section of README file.)" . PHP_EOL;
             $err .= "If the module is already installed, ";
             $err .= "please check if the attribute \"modelClass\" defines an available Model class." . PHP_EOL;
             $this->stderr($err, Console::FG_RED);
             Yii::$app->end(1);
         } elseif (!in_array($action, array_keys($this->installerActions))) {
             $err = 'Only actions: ' . implode(', ', array_keys($this->installerActions));
             $err .= ' are available in current installer mode.' . PHP_EOL;
             $err .= 'Please set option "installerMode" to false (default) to use other commands.' . PHP_EOL;
             $this->stderr($err, Console::FG_RED);
             Yii::$app->end(1);
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
开发者ID:thinker-g,项目名称:yii2-hermes-mailing,代码行数:39,代码来源:DefaultController.php


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