本文整理汇总了PHP中Index::setType方法的典型用法代码示例。如果您正苦于以下问题:PHP Index::setType方法的具体用法?PHP Index::setType怎么用?PHP Index::setType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Index
的用法示例。
在下文中一共展示了Index::setType方法的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);
}
示例2: actionCreateSimple
public function actionCreateSimple()
{
// Get post vars
$indexName = Yii::app()->request->getPost('index');
$type = Yii::app()->request->getPost('type');
$columns = (array) Yii::app()->request->getPost('columns');
$response = new AjaxResponse();
try {
$index = new Index();
$index->throwExceptions = true;
$index->TABLE_SCHEMA = $this->schema;
$index->TABLE_NAME = $this->table;
$index->INDEX_NAME = $indexName;
$index->setType($type);
$index->columns = $this->getColumnsFromRequest();
$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}' => $indexName)), $ex->getText(), $ex->getSql());
}
$this->sendJSON($response);
}
示例3: 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);
}
示例4: 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());
}