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


PHP Table::columns方法代码示例

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


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

示例1: _getRecords

 /**
  * Converts the internal records into data used to generate a query.
  *
  * @return array
  */
 protected function _getRecords()
 {
     $fields = $values = $types = [];
     $columns = $this->_schema->columns();
     foreach ($this->records as $record) {
         $fields = array_merge($fields, array_intersect(array_keys($record), $columns));
     }
     $fields = array_values(array_unique($fields));
     foreach ($fields as $field) {
         $types[$field] = $this->_schema->column($field)['type'];
     }
     $default = array_fill_keys($fields, null);
     foreach ($this->records as $record) {
         $values[] = array_merge($default, $record);
     }
     return [$fields, $values, $types];
 }
开发者ID:taodf,项目名称:cakephp,代码行数:22,代码来源:TestFixture.php

示例2: createTableSql

 public function createTableSql(Table $table, $columns, $constraints, $indexes)
 {
     $content = array_merge($columns, $constraints);
     $content = implode(",\n", array_filter($content));
     $tableName = $table->name();
     if ($this->_driver->autoQuoting()) {
         $tableName = $this->_driver->quoteIdentifier($tableName);
     }
     $out = [sprintf("CREATE TABLE %s (\n%s\n)", $tableName, $content)];
     foreach ($indexes as $index) {
         $out[] = $index;
     }
     foreach ($table->columns() as $column) {
         $columnData = $table->column($column);
         if ($this->_driver->autoQuoting()) {
             $column = $this->_driver->quoteIdentifier($column);
         }
         if (isset($columnData['comment'])) {
             $out[] = sprintf('COMMENT ON COLUMN %s.%s IS %s', $tableName, $column, $this->_driver->schemaValue($columnData['comment']));
         }
     }
     return $out;
 }
开发者ID:hevertonfreitas,项目名称:cakephp-3-oracle,代码行数:23,代码来源:OracleSchema.php

示例3: _generateRecords

 /**
  * Generate String representation of Records
  *
  * @param \Cake\Database\Schema\Table $table Table schema array
  * @param int $recordCount The number of records to generate.
  * @return array Array of records to use in the fixture.
  */
 protected function _generateRecords(Table $table, $recordCount = 1)
 {
     $records = [];
     for ($i = 0; $i < $recordCount; $i++) {
         $record = [];
         foreach ($table->columns() as $field) {
             $fieldInfo = $table->column($field);
             $insert = '';
             switch ($fieldInfo['type']) {
                 case 'decimal':
                     $insert = $i + 1.5;
                     break;
                 case 'biginteger':
                 case 'integer':
                 case 'float':
                     $insert = $i + 1;
                     break;
                 case 'string':
                 case 'binary':
                     $isPrimary = in_array($field, $table->primaryKey());
                     if ($isPrimary) {
                         $insert = Text::uuid();
                     } else {
                         $insert = "Lorem ipsum dolor sit amet";
                         if (!empty($fieldInfo['length'])) {
                             $insert = substr($insert, 0, (int) $fieldInfo['length'] - 2);
                         }
                     }
                     break;
                 case 'timestamp':
                     $insert = time();
                     break;
                 case 'datetime':
                     $insert = date('Y-m-d H:i:s');
                     break;
                 case 'date':
                     $insert = date('Y-m-d');
                     break;
                 case 'time':
                     $insert = date('H:i:s');
                     break;
                 case 'boolean':
                     $insert = 1;
                     break;
                 case 'text':
                     $insert = "Lorem ipsum dolor sit amet, aliquet feugiat.";
                     $insert .= " Convallis morbi fringilla gravida,";
                     $insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
                     $insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
                     $insert .= " vestibulum massa neque ut et, id hendrerit sit,";
                     $insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
                     $insert .= " duis vestibulum nunc mattis convallis.";
                     break;
                 case 'uuid':
                     $insert = Text::uuid();
                     break;
             }
             $record[$field] = $insert;
         }
         $records[] = $record;
     }
     return $records;
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:70,代码来源:FixtureTask.php

示例4: createTableSql

 /**
  * {@inheritDoc}
  */
 public function createTableSql(Table $table, $columns, $constraints, $indexes)
 {
     $content = array_merge($columns, $constraints);
     $content = implode(",\n", array_filter($content));
     $tableName = $this->_driver->quoteIfAutoQuote($table->name());
     $temporary = $table->temporary() ? ' TEMPORARY ' : ' ';
     $out = [];
     $out[] = sprintf("CREATE%sTABLE %s (\n%s\n)", $temporary, $tableName, $content);
     foreach ($indexes as $index) {
         $out[] = $index;
     }
     foreach ($table->columns() as $column) {
         $columnData = $table->column($column);
         if (isset($columnData['comment'])) {
             $out[] = sprintf('COMMENT ON COLUMN %s.%s IS %s', $tableName, $this->_driver->quoteIfAutoQuote($column), $this->_driver->schemaValue($columnData['comment']));
         }
     }
     $pk = $this->_getPrimaryKey($table);
     if ($pk) {
         $fieldName = $pk['columns'][0];
         $out = Hash::merge($out, $this->getCreateAutoincrementSql($fieldName, $table->name()));
     }
     return $out;
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:27,代码来源:OracleSchema.php

示例5: get_data

 public function get_data()
 {
     $this->auth();
     $this->layout = false;
     $this->render(false);
     $model_name = Inflector::camelize($this->request->data['model']);
     $Model = TableRegistry::get($model_name);
     $table = new Table(Inflector::tableize($this->request->data['model']));
     $cols = $table->columns();
     //die(var_dump($Model));
     $order = [];
     if ($Model->hasField('sort')) {
         $order[$model_name . '.sort'] = 'ASC';
     }
     if ($Model->hasField('name')) {
         $order[$model_name . '.name'] = 'ASC';
     }
     if (isset($this->request->data['order_field']) && isset($this->request->data['order_dir'])) {
         $order = [$model_name . '.' . $this->request->data['order_field'] => $this->request->data['order_dir']];
     }
     if (isset($this->request->data['belongsTo'])) {
         $conditions = [];
         foreach ($this->request->data['belongsTo'] as $key => $val) {
             if ($val === 'null') {
                 $val = null;
             }
             $conditions[$key] = $val;
         }
         $result = $Model->find('all', ['conditions' => $conditions, 'order' => $order])->toArray();
     } else {
         $result = $Model->find('all', ['order' => $order])->toArray();
     }
     if ($result) {
         die(json_encode(["data" => $result, "status" => "success"]));
     }
     die(json_encode(["data" => [], "status" => "fail"]));
 }
开发者ID:dlowetz,项目名称:asset-preview,代码行数:37,代码来源:ManagerController.php

示例6: testConstructWithColumns

 /**
  * Test construction with columns
  *
  * @return void
  */
 public function testConstructWithColumns()
 {
     $columns = ['id' => ['type' => 'integer', 'length' => 11], 'title' => ['type' => 'string', 'length' => 255]];
     $table = new Table('articles', $columns);
     $this->assertEquals(['id', 'title'], $table->columns());
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:11,代码来源:TableTest.php

示例7: _generateSchema

 /**
  * Generates a string representation of a schema.
  *
  * @param \Cake\Database\Schema\Table $table Table schema.
  * @return string fields definitions
  */
 protected function _generateSchema(Table $table)
 {
     $cols = $indexes = $constraints = [];
     foreach ($table->columns() as $field) {
         $fieldData = $table->column($field);
         $properties = implode(', ', $this->_values($fieldData));
         $cols[] = "            '{$field}' => [{$properties}],";
     }
     foreach ($table->indexes() as $index) {
         $fieldData = $table->index($index);
         $properties = implode(', ', $this->_values($fieldData));
         $indexes[] = "                '{$index}' => [{$properties}],";
     }
     foreach ($table->constraints() as $index) {
         $fieldData = $table->constraint($index);
         $properties = implode(', ', $this->_values($fieldData));
         $constraints[] = "                '{$index}' => [{$properties}],";
     }
     $options = $this->_values($table->options());
     $content = implode("\n", $cols) . "\n";
     if (!empty($indexes)) {
         $content .= "            '_indexes' => [\n" . implode("\n", $indexes) . "\n            ],\n";
     }
     if (!empty($constraints)) {
         $content .= "            '_constraints' => [\n" . implode("\n", $constraints) . "\n            ],\n";
     }
     if (!empty($options)) {
         $content .= "            '_options' => [\n" . implode(', ', $options) . "\n            ],\n";
     }
     return "[\n{$content}        ]";
 }
开发者ID:scherersoftware,项目名称:cakephp-schema,代码行数:37,代码来源:SchemaSaveTask.php


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