本文整理汇总了PHP中Doctrine::createTablesFromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine::createTablesFromArray方法的具体用法?PHP Doctrine::createTablesFromArray怎么用?PHP Doctrine::createTablesFromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine
的用法示例。
在下文中一共展示了Doctrine::createTablesFromArray方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
public function setup()
{
$db = $this->databasemanager->getDatabase('doctrine');
/* @var $db sfDoctrineDatabase */
// Special Handling for postgre, since droping even when closing the connection, fails with
// SQLSTATE[55006]: Object in use: 7 ERROR: database "cs_doctrine_act_as_sortable_test" is being accessed by other users DETAIL: There are 1 other session(s) using the database.
if ($db->getDoctrineConnection() instanceof Doctrine_Connection_Pgsql) {
try {
$db->getDoctrineConnection()->createDatabase();
} catch (Exception $e) {
}
$export = new Doctrine_Export_Pgsql($db->getDoctrineConnection());
$import = new Doctrine_Import_Pgsql($db->getDoctrineConnection());
$tablenames = array(SortableArticleTable::getInstance()->getTableName(), SortableArticleUniqueByTable::getInstance()->getTableName(), SortableArticleCategoryTable::getInstance()->getTableName());
foreach ($tablenames as $tablename) {
if ($import->tableExists($tablename)) {
$export->dropTable($tablename);
}
}
} else {
try {
// ignore error if database does not yet exist (clean CI-env)
$db->getDoctrineConnection()->dropDatabase();
} catch (Exception $e) {
}
$db->getDoctrineConnection()->createDatabase();
}
// Using Doctrine instead of Doctrine_Core keeps it symfony 1.2 compatible, which uses
Doctrine::loadModels(dirname(__FILE__) . '/../fixtures/project/lib/model/doctrine', Doctrine::MODEL_LOADING_CONSERVATIVE);
Doctrine::createTablesFromArray(Doctrine::getLoadedModels());
Doctrine::loadData(dirname(__FILE__) . '/../fixtures/project/data/fixtures/categories.yml');
}
示例2: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$this->logSection('doctrine', 'created tables successfully');
$databaseManager = new sfDatabaseManager($this->configuration);
Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine', Doctrine::MODEL_LOADING_CONSERVATIVE);
Doctrine::createTablesFromArray(Doctrine::getLoadedModels());
}
示例3: testCachedResultsAreSpecificToDsn
public function testCachedResultsAreSpecificToDsn()
{
$cacheDriver = new Doctrine_Cache_Array();
$conn1 = Doctrine_Manager::connection('sqlite::memory:', 'conn_1');
$conn1->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
$conn2 = Doctrine_Manager::connection('sqlite::memory:', 'conn_2');
$conn2->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
$this->assertNotEqual($conn1, $conn2);
$manager = Doctrine_Manager::getInstance();
$manager->setCurrentConnection('conn_1');
$this->assertEqual($conn1, Doctrine_Manager::connection());
Doctrine::createTablesFromArray(array('Ticket_1706_User'));
$user = new Ticket_1706_User();
$user->name = 'Allen';
$user->save();
$manager->setCurrentConnection('conn_2');
$this->assertEqual($conn2, Doctrine_Manager::connection());
Doctrine::createTablesFromArray(array('Ticket_1706_User'));
$user = new Ticket_1706_User();
$user->name = 'Bob';
$user->save();
$manager->setCurrentConnection('conn_1');
$u1 = Doctrine_Query::create()->from('Ticket_1706_User u')->useResultCache()->execute();
$this->assertEqual(1, count($u1));
$this->assertEqual('Allen', $u1[0]->name);
$manager->setCurrentConnection('conn_2');
$u2 = Doctrine_Query::create()->from('Ticket_1706_User u')->useResultCache()->execute();
$this->assertEqual(1, count($u2));
$this->assertEqual('Bob', $u2[0]->name);
}
示例4: migrate
public function migrate()
{
$conn = Doctrine_Manager::connection();
if (!$conn->import->tableExists('simple_route')) {
Doctrine::createTablesFromArray(array('SimpleRoute'));
$this->postInstall();
}
}
示例5: setUpCarsAndDrivers
public function setUpCarsAndDrivers()
{
Doctrine::createTablesFromArray(array('Car', 'Driver'));
$bmw = new Car();
$bmw->make = 'BMW';
$bmw->save();
$this->cars['bmw'] = $bmw;
$audi = new Car();
$audi->make = 'Audi';
$audi->save();
$this->cars['audi'] = $audi;
$kiro = new Driver();
$kiro->name = 'Kiril Zyapkov';
$kiro->save();
$this->drivers['kiro'] = $kiro;
$emo = new Driver();
$emo->name = 'Emil Ivanov';
$emo->save();
$this->drivers['emo'] = $emo;
}
示例6: testGeneratorComponentBinding
public function testGeneratorComponentBinding()
{
Doctrine_Manager::connection('sqlite::memory:', 'test_tmp_conn', false);
Doctrine_Manager::getInstance()->bindComponent('I18nGeneratorComponentBinding', 'test_tmp_conn');
Doctrine::createTablesFromArray(array('I18nGeneratorComponentBinding'));
try {
$i = new I18nGeneratorComponentBinding();
$i->name = 'test';
$i->Translation['EN']->title = 'en test';
$i->Translation['FR']->title = 'fr test';
$i->save();
$this->pass();
$this->assertTrue($i->id > 0);
$this->assertEqual($i->Translation['EN']->title, 'en test');
$this->assertEqual($i->Translation['FR']->title, 'fr test');
$this->assertEqual($i->getTable()->getConnection()->getName(), $i->Translation->getTable()->getConnection()->getName());
} catch (Exception $e) {
$this->fail($e->getMessage());
}
}
示例7: install
/**
* Do the actual installation.
*
* Make sure you rollback any changes if your install fails (using uninstall())!
*
* By default, the install routine just installs your models. If that's all you need for your install,
* you don't need to override this function. All models in the directory of your module will be installed.
*
* You do not need to override this class if you are not adding additional functionality to it.
*
* @return array | NULL Array of failures, or NULL if everything is OK
*/
public function install($identifier)
{
$package = Package_Catalog::getPackageByIdentifier($identifier);
if (!empty($package['directory']) and $package['type'] != Package_Manager::TYPE_CORE) {
kohana::log('debug', 'Dynamically adding `' . $package['directory'] . '` to kohana');
$loadedModules = Kohana::config('core.modules');
$modules = array_unique(array_merge($loadedModules, array($package['directory'])));
Kohana::config_set('core.modules', $modules);
if (is_dir($package['directory'] . '/hooks')) {
// Since we're running late, we need to go grab
// the hook files again (sad but true)
$hooks = Kohana::list_files('hooks', TRUE, $package['directory'] . '/hooks');
foreach ($hooks as $file) {
// Load the hook
include_once $file;
}
}
}
// If this package has any models, load them and determine which ones are BASE models (i.e. not extensions of other models)
// Note that we do this because Postgers & Doctrine don't like our polymorphic class extensions and try to create the same
// tables twice.
if (!empty($package['models'])) {
$loadedModels = Doctrine::loadModels($package['directory'] . '/models', Doctrine::MODEL_LOADING_CONSERVATIVE);
}
if (!empty($loadedModels)) {
$models = array();
foreach ($loadedModels as $modelName) {
if (get_parent_class($modelName) == 'Bluebox_Record' or get_parent_class($modelName) == 'Doctrine_Record') {
$models[] = $modelName;
}
}
// If this package has any models of it's own (not extensions) then create the tables!
if (!empty($models)) {
kohana::log('debug', 'Adding table(s) ' . implode(', ', $models));
Doctrine::createTablesFromArray($models);
}
}
}
示例8: catch
}
try {
$tbl = Doctrine::getTable($modelname);
} catch (Exception $e) {
echo "Error!\n" . $e->getMessage() . "\n";
exit(1);
}
try {
$conn->execute('describe ' . $tbl->getTableName());
echo "Table already exists in database!\nDrop table and recreate? (y/n) > ";
$drop = strtolower(trim(fgets(STDIN)));
if ($drop == 'y') {
try {
$conn->execute('drop table ' . $tbl->getTableName());
} catch (Exception $e) {
echo "Unable to drop table! - " . $e->getMessage() . "\n";
exit(1);
}
} else {
exit(0);
}
} catch (Exception $e) {
// table doesn't exist --- good!
}
echo "Creating table ... ";
try {
Doctrine::createTablesFromArray(array($tbl->getClassnameToReturn()));
echo "Success!\n";
} catch (Exception $e) {
echo "Error!\n" . $e->getMessage() . "\n";
}
示例9: createTablesFromArray
/**
*
* Initialize the database
* @return void
*/
public function createTablesFromArray()
{
$models = $this->_getModels();
Doctrine::createTablesFromArray($models);
}
示例10: dirname
<?php
/**
* Script for creating and loading database
*/
include_once dirname(__FILE__) . '/../../../application/bootstrap.php';
echo 'Generating models from schemas' . PHP_EOL;
try {
Doctrine::generateModelsFromYaml('user.yml', APPLICATION_PATH . '/models');
Doctrine::createTablesFromArray(array('User'));
} catch (Exception $e) {
echo 'AN ERROR HAS OCCURED:' . PHP_EOL;
echo $e->getMessage() . PHP_EOL;
return false;
}
// Generally speaking, this script will be run from the command line
return true;
示例11: dirname
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/**
* Document this file.
*
* @author Jason Kinner <jkinner@ringsidenetworks.com>
*/
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../config.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../quiz.class.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '/../answer.class.php';
try {
$dm = Doctrine_Manager::getInstance();
$dm->openConnection($db_url);
// print join(";\n", Doctrine::generateSqlFromArray(
Doctrine::createTablesFromArray(array('Quiz', 'Answer'));
// )).";\n";
print "Done\n";
} catch (Exception $e) {
print $e->getMessage() . "\n";
error_log($e->getTraceAsString());
}