本文整理汇总了PHP中Index::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Index::model方法的具体用法?PHP Index::model怎么用?PHP Index::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Index
的用法示例。
在下文中一共展示了Index::model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionStructure
/**
* Shows the table structure
*/
public function actionStructure()
{
$table = $this->loadTable();
if (!$table instanceof Table) {
$response = new AjaxResponse();
$response->addNotification("error", Yii::t("core", "tableLoadErrorTitle", array("{table}" => $this->table)), Yii::t("core", "tableLoadErrorMessage", array("{table}" => $this->table)));
$response->executeJavaScript("sideBar.loadTables(schema)");
$this->sendJSON($response);
}
// Constraints
if (StorageEngine::check($table->ENGINE, StorageEngine::SUPPORTS_FOREIGN_KEYS)) {
$foreignKeys = array();
$sql = 'SELECT * FROM KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'AND REFERENCED_TABLE_SCHEMA IS NOT NULL';
$table->foreignKeys = ForeignKey::model()->findAllBySql($sql, array('tableSchema' => $table->TABLE_SCHEMA, 'tableName' => $table->TABLE_NAME));
foreach ($table->foreignKeys as $key) {
$foreignKeys[] = $key->COLUMN_NAME;
}
} else {
$foreignKeys = false;
}
// Indices
$sql = 'SELECT * FROM STATISTICS ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'GROUP BY INDEX_NAME ' . 'ORDER BY INDEX_NAME = \'PRIMARY\' DESC, INDEX_NAME';
$table->indices = Index::model()->findAllBySql($sql, array('tableSchema' => $table->TABLE_SCHEMA, 'tableName' => $table->TABLE_NAME));
foreach ($table->indices as $index) {
$index->columns = IndexColumn::model()->findAllByAttributes(array('TABLE_SCHEMA' => $table->TABLE_SCHEMA, 'TABLE_NAME' => $table->TABLE_NAME, 'INDEX_NAME' => $index->INDEX_NAME));
}
// Indices (seperate for each column)
$indicesRaw = Index::model()->findAllByAttributes(array('TABLE_SCHEMA' => $table->TABLE_SCHEMA, 'TABLE_NAME' => $table->TABLE_NAME));
// Triggers
$table->triggers = Trigger::model()->findAllByAttributes(array('EVENT_OBJECT_SCHEMA' => $table->TABLE_SCHEMA, 'EVENT_OBJECT_TABLE' => $table->TABLE_NAME));
$this->render('structure', array('table' => $table, 'canAlter' => Yii::app()->user->privileges->checkTable($table->TABLE_SCHEMA, $table->TABLE_NAME, 'ALTER'), 'foreignKeys' => $foreignKeys, 'indicesRaw' => $indicesRaw));
}
示例2: testUpdatePrimaryKey
public function testUpdatePrimaryKey()
{
// Load index
$index = Index::model()->findByAttributes(array('INDEX_NAME' => 'UNIQUE', 'TABLE_NAME' => 'table4', 'TABLE_SCHEMA' => 'indextest'));
$index->setType('PRIMARY');
// Try saving
$index->save();
// Reload index and load index columns
$index->refresh();
// Check properties
$this->assertEquals('PRIMARY', $index->INDEX_NAME);
$this->assertEquals('PRIMARY', $index->getType());
}
示例3: actionDrop
public function actionDrop()
{
// Get post vars
$indexName = Yii::app()->request->getPost('index');
$response = new AjaxResponse();
try {
$index = Index::model()->findByAttributes(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table, 'INDEX_NAME' => $indexName));
$index->throwExceptions = true;
$sql = $index->delete();
$response->addNotification('success', Yii::t('core', 'successDropIndex', array('{index}' => $index->INDEX_NAME)), null, $sql);
$response->addData('success', true);
} catch (DbException $ex) {
$response->addNotification('error', Yii::t('core', 'errorDropIndex', array('{index}' => $indexName)), $ex->getText(), $ex->getSql());
$response->addData('success', false);
}
$this->sendJSON($response);
}