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


PHP ActiveRecord::tableName方法代码示例

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


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

示例1: findOrderNum

 /**
  * Find and set order numeric
  */
 public function findOrderNum()
 {
     if (!$this->owner->{$this->attribute}) {
         $maxOrderNum = (int) (new Query())->select("MAX({$this->attribute})")->from($this->owner->tableName())->scalar();
         $this->owner->{$this->attribute} = $maxOrderNum + $this->step;
     }
 }
开发者ID:roboapp,项目名称:base,代码行数:10,代码来源:SortableBehavior.php

示例2: init

 public function init()
 {
     $this->id = $this->model->formName();
     $this->action = RequestModule::getPopupUrl(['type' => $this->model->tableName()]);
     $this->fieldConfig = ['template' => '<div class="row">{input}{error}</div>', 'errorOptions' => ['class' => 'errorMessage']];
     parent::init();
 }
开发者ID:tolik505,项目名称:bl,代码行数:7,代码来源:CustomForm.php

示例3: setInsertSort

 public function setInsertSort()
 {
     if (!$this->owner->{$this->attributeName}) {
         $query = $this->getQuery();
         $query->select(new Expression('MAX(' . $this->attributeName . ')'));
         $query->from($this->owner->tableName());
         $this->owner->{$this->attributeName} = $query->scalar() + 1;
     }
 }
开发者ID:nanodesu88,项目名称:yii2-activerecord-sort,代码行数:9,代码来源:SortBehavior.php

示例4: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     //get config from instance
     if ($this->stateConfig === null || $this->stateAttribute === null) {
         $this->modelInstance = new $this->owner->modelClass();
         $this->stateAttribute = $this->modelInstance->tableName() . '.' . $this->modelInstance->stateAttribute;
         $this->stateConfig = $this->modelInstance->stateConfig;
     }
 }
开发者ID:highestgoodlikewater,项目名称:yii2-toolbox,代码行数:13,代码来源:StateQueryBehavior.php

示例5: search

 public function search($params)
 {
     /* @var $query \yii\db\ActiveQuery */
     $query = $this->baseModel->find();
     $table_inheritance_joined = false;
     $dataProvider = new ActiveDataProvider(['query' => &$query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!$this->load($params)) {
         return $dataProvider;
     }
     $object = Object::getForClass($this->baseModel->className());
     $baseModelTableName = $this->baseModel->tableName();
     $eavJoinsCount = 0;
     $osvJoinsCount = 0;
     foreach ($this->propertyGroups as $groupId => $properties) {
         foreach ($properties as $key => $propertyValue) {
             /** @var \app\properties\PropertyValue $propertyValue */
             $prop = Property::findById($propertyValue->property_id);
             if (empty($this->{$prop->key}) === true && $this->{$prop->key} !== '0') {
                 continue;
             }
             // determine property storage type and join needed table if needed
             if ($prop->is_column_type_stored) {
                 if ($table_inheritance_joined === false) {
                     $table_inheritance_joined = true;
                     $query->join('INNER JOIN', $object->column_properties_table_name . ' ti', 'ti.object_model_id = ' . $baseModelTableName . '.id');
                 }
                 if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) {
                     $query->andFilterWhere(['like', 'ti.' . $prop->key, $this->{$prop->key}]);
                 } else {
                     $query->andFilterWhere(['ti.' . $prop->key => $this->{$prop->key}]);
                 }
             } elseif ($prop->is_eav) {
                 $eavJoinsCount++;
                 $eavTableName = 'eav' . $eavJoinsCount;
                 $key = 'key' . $eavJoinsCount;
                 $query->join('INNER JOIN', "{$object->eav_table_name} {$eavTableName}", $eavTableName . '.object_model_id = ' . $baseModelTableName . ".id AND {$eavTableName}.key=:{$key}", [$key => $prop->key]);
                 if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) {
                     $query->andFilterWhere(['like', $eavTableName . '.value', $this->{$prop->key}]);
                 } else {
                     // numeric - direct match
                     $query->andFilterWhere([$eavTableName . '.value' => $this->{$prop->key}]);
                 }
             } elseif ($prop->has_static_values) {
                 $osvJoinsCount++;
                 $osvTableName = 'osv' . $osvJoinsCount;
                 $query->join('INNER JOIN', "object_static_values {$osvTableName}", "{$osvTableName}.object_id={$object->id} AND {$osvTableName}.object_model_id={$baseModelTableName}.id");
                 // numeric - direct match
                 $query->andFilterWhere(["{$osvTableName}.property_static_value_id", $this->{$prop->key}]);
             }
         }
     }
     return $dataProvider;
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:53,代码来源:DynamicSearchModel.php

示例6: tableName

 public static function tableName()
 {
     if (self::$_table) {
         return \Yii::$app->getDb()->tablePrefix . self::$_table;
     }
     return parent::tableName();
 }
开发者ID:xswolf,项目名称:baihey,代码行数:7,代码来源:Base.php

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

示例8: tableName

 /**
  * Get table name of SEO data table for ActiveRecord
  * @param ActiveRecord $activeRecord
  * @return string
  */
 public static function tableName(ActiveRecord $activeRecord)
 {
     $tableName = $activeRecord->tableName();
     if (substr($tableName, -2) == '}}') {
         return preg_replace('/{{(.+)}}/', '{{$1_' . self::$tableSuffix . '}}', $tableName);
     } else {
         return $tableName . '_' . self::$tableSuffix;
     }
 }
开发者ID:inblank,项目名称:yii2-seobility,代码行数:14,代码来源:Seo.php

示例9: attach

 /**
  * @inheritdoc
  * @param \yii\db\ActiveRecord $owner
  */
 public function attach($owner)
 {
     //assert owner extends class ActiveRecord
     if (!$owner instanceof ActiveRecord) {
         throw new InvalidConfigException('ArchiveBehavior can only be applied to classes extending \\yii\\db\\ActiveRecord');
     }
     if ($owner->tableSchema->getColumn($this->archiveAttribute) === null) {
         throw new InvalidConfigException(sprintf('The table %s does not contain a column named %s', $owner->tableName(), $this->archiveAttribute));
     }
     parent::attach($owner);
 }
开发者ID:highestgoodlikewater,项目名称:yii2-toolbox,代码行数:15,代码来源:ArchiveBehavior.php

示例10: attributeValue

 public function attributeValue(ActiveRecord $model, $fieldName)
 {
     $complexName = $model->tableName() . '.' . $fieldName;
     $decode = \Yii::$app->params['decode'];
     $key = $model->{$fieldName};
     if ($key !== null && isset($decode[$complexName])) {
         return $decode[$complexName][$key];
     } else {
         return $key;
     }
 }
开发者ID:vastander,项目名称:yii2-eer,代码行数:11,代码来源:AttributeTrait.php

示例11: storeDataRecord

 /**
  * Store data record and track change statistics
  *
  * @param ActiveRecord $ActiveRecord
  *
  * @return bool false if not saved
  */
 protected function storeDataRecord(ActiveRecord $ActiveRecord)
 {
     if ($ActiveRecord->getDirtyAttributes()) {
         $unsaved_record = clone $ActiveRecord;
         // Save record
         if (!$ActiveRecord->save()) {
             // Create error message
             $message = "Save error: " . json_encode($ActiveRecord->errors) . "\n";
             $message .= "Record data: " . json_encode($ActiveRecord->getAttributes()) . "\n";
             trigger_error($message, E_USER_WARNING);
             $this->incStat('error_' . $ActiveRecord->tableName());
             return false;
         }
         // Store statistics
         if ($unsaved_record->isNewRecord) {
             $this->incStat('new_' . $ActiveRecord->tableName());
         } else {
             $this->incStat('update_' . $ActiveRecord->tableName());
         }
     }
     return true;
 }
开发者ID:drsdre,项目名称:yii2-betssonsports,代码行数:29,代码来源:Cache.php

示例12: find

 public static function find()
 {
     $tenantTableName = '{{%tenant}}';
     $field = '';
     $model = parent::find();
     if (parent::tableName() == $tenantTableName) {
         $field = '.id';
     } else {
         $field = '.tenant_id';
     }
     $model->where([parent::tableName() . $field => Yii::$app->session['tenant']]);
     return $model;
 }
开发者ID:antonio74,项目名称:daduu42,代码行数:13,代码来源:TenantActiveRecord.php

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

示例14: dropCaches

 /**
  * @param ActiveRecord $model
  * @param array        $changedAttributes
  */
 public static function dropCaches($model, array $changedAttributes = [])
 {
     self::initialize();
     $attrs = $model->getAttributes();
     $changed = [];
     if ($changedAttributes) {
         $attrNames = array_keys($changedAttributes);
         foreach ($attrNames as $attrName) {
             if (array_key_exists($attrName, $attrs)) {
                 $changed[$attrName] = $attrs[$attrName];
             }
         }
     }
     $args = [$model->tableName(), json_encode($attrs, self::$jsonOptions), json_encode($changed, self::$jsonOptions)];
     CacheHelper::evalSHA(self::$shaInvalidate, $args, 0);
 }
开发者ID:sitkoru,项目名称:yii2-ar-cache,代码行数:20,代码来源:ActiveQueryCacheHelper.php

示例15: updateOwner

 /**
  * @param integer $fileId
  * @return int
  * @throws Exception
  */
 protected function updateOwner($fileId)
 {
     $this->owner->updateAttributes([$this->attribute => $fileId]);
     $sql = "\n            UPDATE " . $this->owner->tableName() . "\n            SET " . $this->attribute . " = :file\n            WHERE id = :id\n        ";
     return Yii::$app->db->createCommand($sql)->bindValue(':file', $fileId)->bindValue(':id', $this->owner->primaryKey)->execute();
 }
开发者ID:stee1cat,项目名称:yii2-file-attachment,代码行数:11,代码来源:FileBehavior.php


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