本文整理汇总了PHP中Doctrine_Core::createTablesFromModels方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Core::createTablesFromModels方法的具体用法?PHP Doctrine_Core::createTablesFromModels怎么用?PHP Doctrine_Core::createTablesFromModels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Core
的用法示例。
在下文中一共展示了Doctrine_Core::createTablesFromModels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initDoctrine
protected function _initDoctrine()
{
$config = $this->getOptions();
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET, 'utf8');
$manager->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE, 'utf8_unicode_ci');
$manager->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_TYPE, 'INNODB');
$manager->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, false);
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
// enable validation on save()
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
if ($config['doctrine']['cache']) {
$cacheDriver = new Doctrine_Cache_Apc();
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
}
$conn = Doctrine_Manager::connection($config['doctrine']['dsn']);
$conn->setCharset('utf8');
try {
Doctrine_Core::createDatabases();
} catch (Exception $e) {
}
$conn = Doctrine_Core::loadModels(APPLICATION_PATH . '/models', Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
$conn = Doctrine_Core::createTablesFromModels();
return $manager;
}
示例2: generateTables
public function generateTables()
{
$this->removeTables();
Doctrine_Core::createTablesFromModels(MODELS);
FlashComponent::set('info', 'Generate Table terminé.');
$this->redirect(array('action' => 'index'));
}
示例3: setUp
protected function setUp()
{
$this->classLoader = Zend_Loader_Autoloader::getInstance();
$this->classLoader->registerNamespace('Doctrine_');
if (!class_exists('Doctrine_Manager')) {
$this->markTestSkipped('Doctrine 1.2.x installation not found in include_path');
}
// create in memory connection
Doctrine_Manager::connection("sqlite::memory:", 'doctrine');
// create tables for account model
Doctrine_Core::createTablesFromModels(dirname(__FILE__) . "/_files/models/");
}
示例4: createTablesFromModels
/**
* Create Tables from models for given module.
*
* @param string $modname Module name.
* @param string $path Optional force path to Model directory (used by plugins).
*
* @return void
*/
public static function createTablesFromModels($modname, $path = null)
{
$modname = isset($modname) ? strtolower((string) $modname) : '';
$modinfo = ModUtil::getInfoFromName($modname);
$osdir = DataUtil::formatForOS($modinfo['directory']);
$base = $modinfo['type'] == ModUtil::TYPE_MODULE ? 'modules' : 'system';
$dm = Doctrine_Manager::getInstance();
$save = $dm->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING);
$dm->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
$path = is_null($path) ? "{$base}/{$osdir}/lib/{$osdir}/Model" : "{$base}/{$osdir}/{$path}";
Doctrine_Core::createTablesFromModels(realpath($path));
$dm->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, $save);
}
示例5: setUp
static function setUp()
{
try {
Doctrine_Core::dropDatabases();
} catch (Exception $e) {
}
Doctrine_Manager::connection()->clear();
try {
Doctrine_Core::createDatabases();
} catch (Exception $e) {
}
Doctrine_Core::loadModels(APPLICATION_PATH . '/models', Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
Doctrine_Core::createTablesFromModels();
}
示例6: initialize
function initialize()
{
// bootstrap Doctrine
require_once dirname(__FILE__) . '/vendor/doctrine/doctrine1/lib/Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
$this->manager = Doctrine_Manager::getInstance();
// set connection
$this->con = Doctrine_Manager::connection('sqlite::memory:');
// setup autoloading
$this->manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
// import db
try {
$this->manager->dropDatabases();
} catch (Doctrine_Export_Exception $e) {
// do nothing; it's probably the first time the test is run
}
$this->manager->createDatabases();
Doctrine_Core::createTablesFromModels(dirname(__FILE__) . '/models');
}
示例7: setUp
public function setUp()
{
if (!extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('Requires PDO_Sqlite extension');
}
$this->_request = new Zend_Db_Profiler_FirebugTest_Request();
$this->_response = new Zend_Db_Profiler_FirebugTest_Response();
$channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
$channel->setRequest($this->_request);
$channel->setResponse($this->_response);
// try to autoload doctrine
Zend_Loader_Autoloader::getInstance()->registerNamespace('Doctrine_');
if (!class_exists('Doctrine_Manager')) {
$this->markTestSkipped('Doctrine 1.2.x installation not found in include_path');
}
// create in memory connection
Doctrine_Manager::connection("sqlite::memory:", 'doctrine');
// instantiate plugin
$this->_plugin = new Zle_Controller_Plugin_DoctrineProfilerFirebug();
// create tables for account model
Doctrine_Core::createTablesFromModels(dirname(__FILE__) . "/_files/models/");
}
示例8: createDb
/**
* Create the ShineISP Database
*/
public static function createDb($installsampledata = true)
{
try {
$dbconfig = Shineisp_Main::databaseConfig();
$dsn = Shineisp_Main::getDSN();
$conn = Doctrine_Manager::connection($dsn, 'doctrine');
$conn->execute('SHOW TABLES');
# Lazy loading of the connection. If I execute a simple command the connection to the database starts.
$conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
$conn->setCharset('UTF8');
$dbh = $conn->getDbh();
$models = Doctrine::getLoadedModels();
// Set the current connection
$manager = Doctrine_Manager::getInstance()->setCurrentConnection('doctrine');
if ($conn->isConnected()) {
$migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations');
// Get the latest version set in the migrations directory
$latestversion = $migration->getLatestVersion();
if (empty($latestversion)) {
$latestversion = 0;
}
// Clean the database
$conn->execute('SET FOREIGN_KEY_CHECKS = 0');
foreach ($models as $model) {
$tablename = Doctrine::getTable($model)->getTableName();
$dbh->query("DROP TABLE IF EXISTS {$tablename}");
}
// Create the migration_version table
Doctrine_Manager::getInstance()->getCurrentConnection()->execute('DROP TABLE IF EXISTS `migration_version`;CREATE TABLE `migration_version` (`version` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;INSERT INTO `migration_version` VALUES (' . $latestversion . ')');
// Create all the tables in the database
Doctrine_Core::createTablesFromModels(APPLICATION_PATH . '/models');
// Common resources
Doctrine_Core::loadData(APPLICATION_PATH . '/configs/data/fixtures/commons/', true);
// Sample data
if ($installsampledata) {
$import = new Doctrine_Data_Import(APPLICATION_PATH . '/configs/data/fixtures/');
$import->setFormat('yml');
$import->setModels($models);
$import->doImport(true);
}
$conn->execute('SET FOREIGN_KEY_CHECKS = 1');
// Update the version in the config.xml file previously created
Settings::saveConfig($dbconfig, $latestversion);
} else {
echo "No Connection found";
}
} catch (Exception $e) {
die($e);
}
// return the latest version
return $latestversion;
}
示例9: execute
public function execute()
{
Doctrine_Core::createTablesFromModels($this->getArgument('models_path'));
$this->notify('Created tables successfully');
}
示例10: testExportModelFromDirectory
public function testExportModelFromDirectory()
{
Doctrine_Core::createTablesFromModels(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export');
$this->assertEqual($this->adapter->pop(), 'COMMIT');
$this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD CONSTRAINT cms__category_languages_category_id_cms__category_id FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
}
示例11: exec
public function exec()
{
echo Doctrine_Core::createTablesFromModels($this->getOptionsValue('models-path'));
}
示例12: realpath
<?php
$_test_dir = realpath(dirname(__FILE__) . '/..');
// configuration
require_once dirname(__FILE__) . '/../../../../config/ProjectConfiguration.class.php';
$configuration = ProjectConfiguration::hasActive() ? ProjectConfiguration::getActive() : new ProjectConfiguration(realpath($_test_dir . '/..'));
// autoloader
$autoload = sfSimpleAutoload::getInstance(sfConfig::get('sf_cache_dir') . '/project_autoload.cache');
$autoload->loadConfiguration(sfFinder::type('file')->name('autoload.yml')->in(array(sfConfig::get('sf_symfony_lib_dir') . '/config/config', sfConfig::get('sf_config_dir'))));
$autoload->register();
// lime
include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
//Remove test dirs
$rootdir = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'test_root';
if (is_dir($rootdir)) {
$files = sfFinder::type('any')->maxdepth(4)->in($rootdir);
array_unshift($files, $rootdir);
$fs = new sfFileSystem();
$fs->remove($files);
}
new sfDatabaseManager($configuration);
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::createTablesFromModels(sfConfig::get('sf_lib_dir') . '/model');
示例13: defined
<?php
if (array_key_exists(1, $argv)) {
$env = $argv[1];
} else {
$env = 'production';
}
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__) . '/..'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(BASE_PATH . '/library'), get_include_path())));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$config = array('config' => array(realpath(BASE_PATH . '/configs/application.ini')));
$application = new Zend_Application($env, $config);
$dbConnection = $application->getBootstrap()->bootstrap('Doctrine');
try {
Doctrine_Core::dropDatabases();
} catch (Doctrine_Connection_Mysql_Exception $e) {
error_log('The database did not exists');
}
Doctrine_Core::createDatabases();
$options = $application->getOptions();
$ymlPath = realpath(BASE_PATH . '/Scripts/Yaml/Schema/Koryukan.yml');
$modelsOptions = array('suffix' => '.php', 'generateTableClasses' => true, 'classPrefix' => 'Koryukan_Db_', 'classPrefixFiles' => false, 'baseClassPrefix' => 'Base', 'baseClassesDirectory' => '');
Doctrine_Core::generateModelsFromYaml($ymlPath, $options['db']['objectsPath'], $modelsOptions);
Doctrine_Core::createTablesFromModels($options['db']['objectsPath']);
Doctrine_Core::loadData(BASE_PATH . '/Scripts/Yaml/Data/news.yml');
Doctrine_Core::loadData(BASE_PATH . '/Scripts/Yaml/Data/storeItems.yml');
Doctrine_Core::loadData(BASE_PATH . '/Scripts/Yaml/Data/images.yml');
Doctrine_Core::loadData(BASE_PATH . '/Scripts/Yaml/Data/security.yml');
示例14: define
/**
* Blog - Database Generator
*
* This file contains a script for generating the database for the blog demo.
* Running this script from command line as follows will generate a new database:
*
* <code>
* php generate.php
* </code>
*
* LICENSE
*
* This file is part of the Breeze Framework package and is subject to the new
* BSD license. For full copyright and license information, please see the
* LICENSE file that is distributed with this package.
*
* @author Jeff Welch <whatthejeff@gmail.com>
* @category Blog
* @package Databases
* @copyright Copyright (c) 2010, Breeze Framework
* @license New BSD License
* @version $Id$
*/
define('BREEZE_APPLICATION', realpath(dirname(__FILE__) . '/..'));
require_once BREEZE_APPLICATION . '/models/Doctrine.php';
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::generateModelsFromYaml(BREEZE_APPLICATION . '/databases/schema.yml', BREEZE_APPLICATION . '/models');
Doctrine_Core::createTablesFromModels(BREEZE_APPLICATION . '/models');
示例15: syncdb
public static function syncdb($apps = null, $drop_database = false, $append = true)
{
if (!self::$inited || !self::$connections) {
self::init();
}
if (!$apps) {
$apps = ini('base/INSTALLED_APPS');
}
if (!$apps) {
return true;
}
if ($drop_database) {
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
}
foreach ((array) $apps as $k => $app) {
$app = str_replace('.', '/', $app);
try {
/*
* Generate the models
*/
if (isset($_GET['use_yaml'])) {
$schemas = Package::get_file(sprintf('applications/%s/%s', $app, 'schemas.yml'));
if (!is_file($schemas)) {
continue;
}
Doctrine_Core::generateModelsFromYaml($schemas, Package::get_folder(sprintf('applications/%s/models', $app)), self::$_generate_options);
} else {
try {
import(sprintf('applications/%s/models/generated/*', $app));
} catch (DoesNotExistsException $e) {
continue;
}
}
/*
* syncdb
*/
Doctrine_Core::createTablesFromModels(Package::get_folder(sprintf('applications/%s/models', $app)), self::$_generate_options);
/*
* Insert test data
*/
$dir = Package::get_folder(sprintf('applications/%s/fixtures', $app));
if (is_dir($dir)) {
Doctrine_Core::loadData($dir, $append);
}
} catch (PDOException $e) {
continue;
}
}
}