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


PHP Index::save方法代码示例

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


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

示例1: actionCreate

 public function actionCreate()
 {
     $column = new Column();
     $column->TABLE_NAME = $this->table;
     $table = Table::model()->findByPk(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table));
     if (isset($_POST['Column'])) {
         $column->attributes = $_POST['Column'];
         /*
          * Add index
          */
         $addIndices = array();
         if (isset($_POST['createIndexPrimary'])) {
             $column->createPrimaryKey = true;
         }
         if (isset($_POST['createIndex'])) {
             $addIndices['INDEX'] = $column->COLUMN_NAME;
         }
         if (isset($_POST['createIndexUnique'])) {
             $column->createUniqueKey = true;
         }
         if (isset($_POST['createIndexFulltext'])) {
             $addIndices['FULLTEXT'] = $column->COLUMN_NAME . (array_search($column->COLUMN_NAME, $addIndices) !== false ? '_fulltext' : '');
         }
         if ($sql = $column->save()) {
             $response = new AjaxResponse();
             $response->addNotification('success', Yii::t('core', 'successAddColumn', array('{col}' => $column->COLUMN_NAME)), null, $sql);
             $response->refresh = true;
             foreach ($addIndices as $type => $indexName) {
                 try {
                     $index = new Index();
                     $index->throwExceptions = true;
                     $index->TABLE_NAME = $this->table;
                     $index->TABLE_SCHEMA = $this->schema;
                     $index->INDEX_NAME = $indexName;
                     $index->setType($type);
                     $indexCol = new IndexColumn();
                     $indexCol->COLUMN_NAME = $column->COLUMN_NAME;
                     $index->columns = array($indexCol);
                     $sql = $index->save();
                     $response->addNotification('success', Yii::t('core', 'successCreateIndex', array('{index}' => $index->INDEX_NAME)), null, $sql);
                 } catch (DbException $ex) {
                     $response->addNotification('error', Yii::t('core', 'errorCreateIndex', array('{index}' => $index->INDEX_NAME)), $ex->getText(), $ex->getSql());
                 }
             }
             $this->sendJSON($response);
         }
     }
     $collations = Collation::model()->findAll(array('order' => 'COLLATION_NAME', 'select' => 'COLLATION_NAME, CHARACTER_SET_NAME AS collationGroup'));
     CHtml::generateRandomIdPrefix();
     $data = array('column' => $column, 'table' => $table, 'collations' => $collations);
     $data['formBody'] = $this->renderPartial('formBody', $data, true);
     $this->render('form', $data);
 }
开发者ID:cebe,项目名称:chive,代码行数:53,代码来源:ColumnController.php

示例2: actionCreate

 public function actionCreate()
 {
     $this->layout = false;
     $table = new Table();
     $column = new Column();
     if (isset($_POST['Table'], $_POST['Column'])) {
         $table->attributes = $_POST['Table'];
         $column->attributes = $_POST['Column'];
         /*
          * Add index
          */
         $addIndices = array();
         if (isset($_POST['createIndexPrimary'])) {
             $column->createPrimaryKey = true;
         }
         if (isset($_POST['createIndex'])) {
             $addIndices['INDEX'] = $column->COLUMN_NAME;
         }
         if (isset($_POST['createIndexUnique'])) {
             $column->createUniqueKey = true;
         }
         if (isset($_POST['createIndexFulltext'])) {
             $addIndices['FULLTEXT'] = $column->COLUMN_NAME . (array_search($column->COLUMN_NAME, $addIndices) !== false ? '_fulltext' : '');
         }
         $table->columns = array($column);
         if ($sql = $table->insert()) {
             $response = new AjaxResponse();
             $response->addNotification('success', Yii::t('core', 'successAddTable', array('{table}' => $table->TABLE_NAME)), null, $sql);
             $response->redirectUrl = '#tables/' . $table->TABLE_NAME . '/structure';
             $response->executeJavaScript('sideBar.loadTables(schema);');
             foreach ($addIndices as $type => $indexName) {
                 try {
                     $index = new Index();
                     $index->throwExceptions = true;
                     $index->TABLE_NAME = $table->TABLE_NAME;
                     $index->TABLE_SCHEMA = $this->schema;
                     $index->INDEX_NAME = $indexName;
                     $index->setType($type);
                     $indexCol = new IndexColumn();
                     $indexCol->COLUMN_NAME = $column->COLUMN_NAME;
                     $index->columns = array($indexCol);
                     $sql = $index->save();
                     $response->addNotification('success', Yii::t('core', 'successCreateIndex', array('{index}' => $index->INDEX_NAME)), null, $sql);
                     $response->refresh = true;
                 } catch (DbException $ex) {
                     $response->addNotification('error', Yii::t('core', 'errorCreateIndex', array('{index}' => $index->INDEX_NAME)), $ex->getText(), $ex->getSql());
                 }
             }
             $this->sendJSON($response);
         }
     }
     $collations = Collation::model()->findAll(array('order' => 'COLLATION_NAME', 'select' => 'COLLATION_NAME, CHARACTER_SET_NAME AS collationGroup'));
     CHtml::generateRandomIdPrefix();
     $data = array('table' => $table, 'column' => $column, 'collations' => $collations, 'storageEngines' => StorageEngine::getSupportedEngines());
     $data['columnForm'] = $this->renderPartial('/column/formBody', $data, true);
     $this->render('form', $data);
 }
开发者ID:cebe,项目名称:chive,代码行数:57,代码来源:TableController.php

示例3: testSetTypeFullText

 /**
  * Tests to add an Index to a Column with Type Fulltext
  */
 public function testSetTypeFullText()
 {
     // Create index
     $index = new Index();
     $index->TABLE_NAME = 'table2';
     $index->TABLE_SCHEMA = 'indextest';
     $index->INDEX_NAME = 'newname';
     $index->setType('FULLTEXT');
     // Add new column
     $columns = $index->columns;
     $col = new IndexColumn();
     $col->COLUMN_NAME = 'pk';
     $columns[] = $col;
     $col = new IndexColumn();
     $col->COLUMN_NAME = 'varchar';
     $col->SUB_PART = 10;
     $columns[] = $col;
     $index->columns = $columns;
     // Try saving
     $index->save();
     // Reload index and load index columns
     $index->refresh();
     $cols = IndexColumn::model()->findAllByAttributes(array('TABLE_SCHEMA' => $index->TABLE_SCHEMA, 'TABLE_NAME' => $index->TABLE_NAME, 'INDEX_NAME' => $index->INDEX_NAME));
     // Check properties
     $this->assertEquals('newname', $index->INDEX_NAME);
     $this->assertEquals('FULLTEXT', $index->getType());
 }
开发者ID:cebe,项目名称:chive,代码行数:30,代码来源:IndexTest.php

示例4: actionUpdate

 public function actionUpdate()
 {
     $index = Index::model()->findByAttributes(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table, 'INDEX_NAME' => $this->index));
     if ($index == null) {
         $index = new Index();
         $index->TABLE_SCHEMA = $this->schema;
         $index->TABLE_NAME = $this->table;
         $index->INDEX_NAME = $this->index;
     }
     $table = Table::model()->findByPk(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table));
     if (isset($_POST['Index'])) {
         $index->attributes = $_POST['Index'];
         $index->columns = $this->getColumnsFromRequest();
         if ($sql = $index->save()) {
             $response = new AjaxResponse();
             $response->addNotification('success', Yii::t('core', 'successAlterIndex', array('{index}' => $index->INDEX_NAME)), null, $sql);
             $response->refresh = true;
             $this->sendJSON($response);
         }
     }
     $indexTypes = $table->getSupportedIndexTypes();
     $this->render('form', array('index' => $index, 'indexTypes' => $indexTypes, 'addColumnData' => $this->getColumnSelect($table)));
 }
开发者ID:cebe,项目名称:chive,代码行数:23,代码来源:IndexController.php


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