本文整理汇总了PHP中Schema::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Schema::model方法的具体用法?PHP Schema::model怎么用?PHP Schema::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Schema
的用法示例。
在下文中一共展示了Schema::model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
// Add ordering
$criteria = new CDbCriteria();
$criteria->order = "SCHEMA_NAME ASC";
$schemata = Schema::model()->findAll($criteria);
$dbSeperator = "_";
$items = $root = $children = $items = array();
foreach ($schemata as $schema) {
// Find prefix in name
if ($position = strpos($schema->SCHEMA_NAME, $dbSeperator)) {
$prefix = substr($schema->SCHEMA_NAME, 0, $position);
$root[$prefix] = $prefix;
$children[$prefix][] = substr($schema->SCHEMA_NAME, $position + 1);
} else {
$root[] = $schema->SCHEMA_NAME;
}
}
$i = 0;
foreach ($root as $key => $item) {
$childs = array();
$childrenCount = count($children[$item]);
if ($childrenCount > 1) {
foreach ($children[$item] as $child) {
$childs[] = array('text' => CHtml::link($child, SchemaController::createUrl("/schema/" . $item . $dbSeperator . $child)));
}
} else {
if ($childrenCount == 1) {
$name = $item . $dbSeperator . $children[$item][0];
} else {
$name = $item;
}
$items[] = array('text' => CHtml::link($name, SchemaController::createUrl("/schema/" . $name)));
$i++;
continue;
}
$items[] = array('text' => $childrenCount == 0 ? CHtml::link($item, SchemaController::createUrl("/schema/" . $item)) : $item, 'expanded' => $i == 0 ? true : false, 'children' => $childs);
$i++;
}
$this->data = $items;
parent::init();
}
示例2: testDrop
/**
* Tests to drop a database.
*/
public function testDrop()
{
// Load schema
$schema = Schema::model()->findByPk('schematest2');
// Drop
$this->assertEquals(true, $schema->delete());
// Load again
$this->assertEquals(null, Schema::model()->findByPk('schematest2'));
}
示例3: loadSchema
/**
* Loads the current schema.
*
* @return Schema
*/
public function loadSchema()
{
if (is_null($this->_schema)) {
$this->_schema = Schema::model()->findByPk($this->schema);
if (is_null($this->_schema)) {
throw new CHttpException(500, 'The requested schema does not exist.');
}
}
return $this->_schema;
}
示例4: runForm
/**
* Runs the form.
*/
private function runForm()
{
// @todo: Load all exporters
$exporterNames = array('SqlExporter', 'CsvExporter');
// Instantiate supported exporters
$this->exporters = array();
foreach ($exporterNames as $exporter) {
$supported = call_user_func(array($exporter, 'getSupportedModes'));
if (in_array($this->mode, $supported)) {
$this->exporters[] = new $exporter($this->mode);
}
}
// Create the object list
$this->objects = array();
if ($this->mode == 'objects') {
// Load schema
$schema = Schema::model()->findByPk($this->schema);
// Tables
$tables = $schema->tables;
if (count($tables) > 0) {
$data = array();
foreach ($tables as $table) {
$data['t:' . $table->TABLE_NAME] = $table->TABLE_NAME;
}
$this->objects[Yii::t('core', 'tables')] = $data;
}
// Views
$views = $schema->views;
if (count($views) > 0) {
$data = array();
foreach ($views as $view) {
$data['v:' . $view->TABLE_NAME] = $view->TABLE_NAME;
}
$this->objects[Yii::t('core', 'views')] = $data;
}
// Routines
$routines = $schema->routines;
if (count($routines) > 0) {
$data = array();
foreach ($routines as $routine) {
$data['r:' . $routine->ROUTINE_NAME] = $routine->ROUTINE_NAME;
}
$this->objects[Yii::t('core', 'routines')] = $data;
}
}
}
示例5: actionCreateSchema
public function actionCreateSchema()
{
$schema = new SchemaPrivilege();
$schema->User = $this->user;
$schema->Host = $this->host;
if (isset($_POST['SchemaPrivilege'])) {
$schema->attributes = $_POST['SchemaPrivilege'];
if ($sql = $schema->save()) {
$response = new AjaxResponse();
$response->addNotification('success', Yii::t('core', 'successAddSchemaSpecificPrivileges', array('{user}' => $schema->User, '{host}' => $schema->Host, '{schema}' => $schema->Db)), null);
$response->refresh = true;
$this->sendJSON($response);
}
}
// Prepare all schemata
$schemata = $existing = array();
$allSchemata = Schema::model()->findAll();
$allExisting = SchemaPrivilege::model()->findAllByAttributes(array('User' => $this->user, 'Host' => $this->host));
foreach ($allExisting as $existing1) {
$existing[] = $existing1->Db;
}
foreach ($allSchemata as $schema1) {
if (array_search($schema1->SCHEMA_NAME, $existing) === false) {
$schemata[$schema1->SCHEMA_NAME] = $schema1->SCHEMA_NAME;
}
}
$this->render('schemaPrivilegeForm', array('schema' => $schema, 'schemata' => $schemata));
}