public function __construct() { if (is_null($this->table)) { $database = Connection::getConfig($this->connection); $this->table = $database['prefix'] . Inflector::underscore(get_class($this)); } $this->loadBehaviors($this->behaviors); }
/** * 构造方法 * * @param Connection $connection * @param string|null $databaseName 数据库名,默认使用连接中的数据库 */ public function __construct(Connection $connection, $databaseName = null) { $this->connection = $connection; $this->dbConfig = $connection->getConfig(); if (!$databaseName) { $databaseName = $this->dbConfig['dbname']; } $this->explainSchema($databaseName); }
function install_models(Connection $connection, $package, $models) { $factory = RelationFactory::getInstance(); $factory->prepareRelations($package, $models); $models = $factory->getRelations($connection->getConfig()->getType()); foreach ($models as $model) { if (!install_model($connection, $model)) { return false; } } return true; }
<?php Connection::add(array('development' => array('driver' => 'MySql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'database' => 'spaghetti', 'prefix' => ''), 'production' => array('driver' => 'MySql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'database' => 'spaghetti', 'prefix' => ''), 'test' => array('driver' => 'MySql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'database' => 'spaghetti', 'prefix' => ''))); $env = Config::read('App.environment'); Connection::add('default', Connection::getConfig($env));
public function __construct(Connection $connection) { $this->connection = $connection; $params = $connection->getConfig(); parent::__construct($params); }