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


PHP ActiveRecord::getTableSchema方法代码示例

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


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

示例1: getTableSchema

 public static function getTableSchema()
 {
     $class = get_called_class();
     if (!isset(self::$getTableSchemaCache[$class])) {
         self::$getTableSchemaCache[$class] = parent::getTableSchema();
     }
     return self::$getTableSchemaCache[$class];
 }
开发者ID:laszlovl,项目名称:yii2-staticactiverecord,代码行数:8,代码来源:ActiveRecord.php

示例2: init

 /**
  * @throws \jobbyDb\exception\WrongSchemaException If not all required columns are present in the table
  */
 public function init()
 {
     parent::init();
     // check if all the column names needed are present
     $schema = parent::getTableSchema();
     $columnsPresent = $schema->getColumnNames();
     foreach (static::$columnsRequired as $required) {
         if (!in_array($required, $columnsPresent)) {
             throw new WrongSchemaException("No {$required} column found in '{$this->getTableSchema()}''");
         }
     }
 }
开发者ID:sp-niemand,项目名称:yii2-jobby,代码行数:15,代码来源:StandardModel.php

示例3: getRelationRoutes

 /**
  * @param \yii\db\ActiveRecord $model
  * @param \yii\db\ActiveRecord $relatedModel
  * @param \yii\db\ActiveQuery $relation
  * @return array array with three arrays: create, search and index routes
  */
 public static function getRelationRoutes($model, $relatedModel, $relation)
 {
     if (($route = Yii::$app->crudModelsMap[$relatedModel::className()]) === null) {
         return [null, null, null];
     }
     $allowCreate = Yii::$app->user->can($relatedModel::className() . '.create');
     if ($allowCreate && $model->isNewRecord && $relation->multiple) {
         foreach ($relation->link as $left => $right) {
             if (!$relatedModel->getTableSchema()->getColumn($left)->allowNull) {
                 $allowCreate = false;
                 break;
             }
         }
     }
     if (!$allowCreate) {
         $createRoute = null;
     } else {
         $createRoute = [$route . '/update'];
         if ($relation->multiple) {
             $createRoute['hide'] = implode(',', array_keys($relation->link));
             $scope = $relatedModel->formName();
             $primaryKey = $model->getPrimaryKey(true);
             foreach ($relation->link as $left => $right) {
                 if (!isset($primaryKey[$right])) {
                     continue;
                 }
                 $createRoute[$scope][$left] = $primaryKey[$right];
             }
         }
     }
     $parts = explode('\\', $relatedModel::className());
     $relatedModelClass = array_pop($parts);
     $relatedSearchModelClass = implode('\\', $parts) . '\\search\\' . $relatedModelClass;
     $searchRoute = !class_exists($relatedSearchModelClass) ? null : [$route . '/relation', 'per-page' => 10, 'relation' => $relation->inverseOf, 'id' => Action::exportKey($model->getPrimaryKey()), 'multiple' => $relation->multiple ? 'true' : 'false'];
     $indexRoute = [$route . '/index'];
     return [$createRoute, $searchRoute, $indexRoute];
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:43,代码来源:FormBuilder.php

示例4: getFormElements

 /**
  * Format same as kartik\builder\Form::$attributes
  * @param ActiveRecord $model
  * @return array
  *
  * @see kartik\builder\Form::$attributes
  */
 public function getFormElements($model)
 {
     $res = [];
     $attributes = $model->getAttributes();
     foreach ($model->getTableSchema()->primaryKey as $pk) {
         unset($attributes[$pk]);
     }
     $attributes = array_keys($attributes);
     foreach ($attributes as $attribute) {
         $res[$attribute]['type'] = Form::INPUT_TEXT;
     }
     $res[] = $this->getActionRow($model);
     return $res;
 }
开发者ID:e96,项目名称:yii2-madmin,代码行数:21,代码来源:MAdminController.php

示例5: getAttributeWidget

 /**
  * Get attributes widget.
  *
  * @param \yii\db\ActiveRecord $model Model
  * @param string $attribute Model attribute
  * @return null|string|object
  */
 public function getAttributeWidget($model, $attribute)
 {
     if ($this->attributeWidgets !== null) {
         if (isset($this->attributeWidgets->{$attribute})) {
             return $this->attributeWidgets->{$attribute};
         } else {
             $tableSchema = $model->getTableSchema();
             $column = $tableSchema->columns[$attribute];
             if ($column->phpType === 'boolean') {
                 return 'checkbox';
             } elseif ($column->type === 'text') {
                 return 'textarea';
             } elseif (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
                 return 'password';
             } else {
                 return 'text';
             }
         }
     }
     $attributeWidgets = [];
     if (method_exists($model, 'attributeWidgets')) {
         $attributeWidgets = $model->attributeWidgets();
     }
     $data = [];
     if (!empty($attributeWidgets)) {
         foreach ($attributeWidgets as $item) {
             if (isset($item[0]) && isset($item[1])) {
                 $data[$item[0]] = $item[1];
                 $data[$item[0] . 'Options'] = $item;
             }
         }
     }
     $this->attributeWidgets = (object) $data;
     return $this->getAttributeWidget($model, $attribute);
 }
开发者ID:janisto,项目名称:yii2-ycm,代码行数:42,代码来源:Module.php

示例6: getPkColumnName

 /**
  * Get PK column name
  * @param ActiveRecord $model
  * @return mixed
  */
 public static function getPkColumnName(ActiveRecord $model)
 {
     return $model->getTableSchema()->primaryKey[0];
 }
开发者ID:vladdnepr,项目名称:yii2-ycm,代码行数:9,代码来源:ModelHelper.php

示例7: excludeField

 /**
  * @param ActiveRecord $model
  */
 protected function excludeField($model, $addition = '')
 {
     $this->fieldExclude = ArrayHelper::merge(is_array($this->excludedField) ? $this->excludedField : [$this->excludedField], $this->fieldExclude);
     if (is_callable($this->excludeFieldCallback)) {
         $func = $this->excludeFieldCallback;
         $result = $func($this);
         $result = $result ? is_array($result) ? $result : [$result] : [];
         $this->fieldExclude = ArrayHelper::merge($this->fieldExclude, $result);
     }
     $this->fieldExclude = ArrayHelper::merge($this->fieldExclude, $model->getTableSchema()->primaryKey);
     $behaviors = $model->getBehaviors();
     foreach ($behaviors as $_next) {
         $_nextCopy = $_next;
         $_next = (array) $_next;
         $_next['class'] = $_nextCopy->className();
         if ($_next['class'] === BlameableBehavior::className()) {
             if (isset($_next['updatedByAttribute'])) {
                 if (!empty($_next['updatedByAttribute'])) {
                     $this->fieldExclude[] = $addition . $_next['updatedByAttribute'];
                 }
             } else {
                 $this->fieldExclude[] = $addition . 'updated_by';
             }
             if (isset($_next['createdByAttribute'])) {
                 if (!empty($_next['createdByAttribute'])) {
                     $this->fieldExclude[] = $addition . $_next['createdByAttribute'];
                 }
             } else {
                 $this->fieldExclude[] = $addition . 'created_by';
             }
         } else {
             if ($_next['class'] === TimestampBehavior::className()) {
                 if (isset($_next['updatedAtAttribute'])) {
                     if (!empty($_next['updatedAtAttribute'])) {
                         $this->fieldExclude[] = $addition . $_next['updatedAtAttribute'];
                     }
                 } else {
                     $this->fieldExclude[] = $addition . 'updated_at';
                 }
                 if (isset($_next['createdAtAttribute'])) {
                     if (!empty($_next['createdAtAttribute'])) {
                         $this->fieldExclude[] = $addition . $_next['createdAtAttribute'];
                     }
                 } else {
                     $this->fieldExclude[] = $addition . 'created_at';
                 }
             } else {
                 if ($_next['class'] === PhoneInputBehavior::className()) {
                     if (!$this->searchColumn($_next['phoneAttribute'])) {
                         $this->columns[] = new WidgetsCrud(['fieldName' => $_next['phoneAttribute'], 'widgetType' => 'phone']);
                     }
                 } else {
                     if ($_next['class'] === UploadBehavior::className()) {
                         if (!is_array($this->hasUploadBehavior)) {
                             $this->hasUploadBehavior = ['attributes' => []];
                         }
                         $this->hasUploadBehavior['attributes'][] = isset($_next['attribute']) ? $_next['attribute'] : $_next['attribute'];
                         $this->hasUploadBehavior[] = $_next['pathAttribute'];
                         $this->hasUploadBehavior[] = $_next['baseUrlAttribute'];
                         $this->fieldExclude[] = $addition . $_next['pathAttribute'];
                         $this->fieldExclude[] = $addition . $_next['baseUrlAttribute'];
                         if (!$this->searchColumn($this->hasUploadBehavior)) {
                             $this->columns[] = new WidgetsCrud(['fieldName' => $addition . $_next['attribute'], 'widgetType' => 'upload']);
                         }
                         if (isset($this->columnUsed['upload']) && ($uses = $this->columnUsed['upload'])) {
                             if (isset($uses['expression'])) {
                                 $this->expressions = ArrayHelper::merge($this->expressions, $uses['expression']);
                                 unset($this->columnUsed['expression']);
                             }
                         }
                         $this->used = ArrayHelper::merge($this->used, $uses);
                     } else {
                         if ($_next['class'] === 'omgdef\\multilingual\\MultilingualBehavior') {
                             $this->isMultilingual = true;
                             $this->languageField = $_next['languageField'];
                             $this->translateAttribute = $_next['attributes'];
                             $this->relationField = $_next['langForeignKey'];
                             $class = $_next['langClassName'] . ($_next['dynamicLangClass'] ? isset($_next['langClassSuffix ']) ? $_next['langClassSuffix '] : '' : '');
                             $this->relationClass = $class;
                             if (class_exists($class)) {
                                 /** @var ActiveRecord $class */
                                 $class = new $class();
                                 $this->translateTable = $class::tableName();
                             } else {
                                 $this->translateTable = $_next['tableName'];
                             }
                             $this->excludeField($class, 'translations.');
                         }
                     }
                 }
             }
         }
     }
     $this->columnUsed = ArrayHelper::merge($this->columnUsed, $this->widgetsUseClass);
 }
开发者ID:infinitydevphp,项目名称:infinity-gii,代码行数:98,代码来源:Generator.php


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