本文整理汇总了PHP中yii\db\Connection::className方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::className方法的具体用法?PHP Connection::className怎么用?PHP Connection::className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Connection
的用法示例。
在下文中一共展示了Connection::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
$this->db = Instance::ensure($this->db, Connection::className());
parent::init();
// Note the default configuration data value will not store to database.
$this->data = array_merge($this->loadData(), $this->data);
}
示例2: init
public function init()
{
parent::init();
$this->i2db = Instance::ensure($this->i2db, Connection::className());
$this->infodb = Instance::ensure($this->infodb, Connection::className());
$this->db46 = Instance::ensure($this->db46, Connection::className());
}
示例3: __construct
public function __construct($db = 'db')
{
$this->db = Instance::ensure($db, Connection::className());
$this->generator = new Generator();
$this->dbHelper = new Migration(['db' => $this->db]);
$this->generatorConfigurator = new GeneratorConfigurator();
}
示例4: init
/**
* Initializes the migration.
* This method will set [[db]] to be the 'db' application component, if it is `null`.
*/
public function init()
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::className());
$this->db->getSchema()->refresh();
$this->db->enableSlaves = false;
}
示例5: init
public function init()
{
parent::init();
$db = Instance::ensure($this->db, Connection::className());
$query = new Query();
$this->ticket = $query->select(['*'])->from($this->table)->createCommand($db)->queryAll();
}
示例6: setUp
protected function setUp()
{
parent::setUp();
$this->mockApplication();
Yii::$app->set('db', ['class' => Connection::className(), 'dsn' => 'sqlite::memory:']);
Yii::$app->db->createCommand()->createTable('session', ['id' => 'string', 'expire' => 'integer', 'data' => 'text', 'user_id' => 'integer'])->execute();
}
示例7: init
/**
* Initializes the DbMessageSource component.
* This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
* Configured [[cache]] component would also be initialized.
* @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid.
*/
public function init()
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::className());
if ($this->enableCaching) {
$this->cache = Instance::ensure($this->cache, Cache::className());
}
}
示例8: mockApplication
/**
* Populates Yii::$app with a new application
* The application will be destroyed on tearDown() automatically.
* @param array $config The application configuration, if needed
* @param string $appClass name of the application class to create
*/
protected function mockApplication($config = [], $appClass = '\\yii\\console\\Application')
{
new $appClass(ArrayHelper::merge(['id' => 'testapp', 'basePath' => __DIR__, 'vendorPath' => '../../vendor', 'controllerMap' => ['deferred' => ['class' => DeferredController::className()]], 'components' => ['mutex' => ['class' => 'yii\\mutex\\MysqlMutex', 'autoRelease' => false], 'db' => ['class' => Connection::className(), 'dsn' => 'mysql:host=localhost;dbname=yii2_deferred_tasks', 'username' => 'root', 'password' => ''], 'cache' => ['class' => 'yii\\caching\\FileCache']]], $config));
Yii::$app->cache->flush();
Yii::$app->getDb()->open();
Yii::$app->runAction('migrate/down', [99999, 'interactive' => 0, 'migrationPath' => __DIR__ . '/../src/migrations/']);
Yii::$app->runAction('migrate/up', ['interactive' => 0, 'migrationPath' => __DIR__ . '/../src/migrations/']);
}
示例9: beforeAction
/**
* @inheritdoc
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->db = Instance::ensure($this->db, Connection::className());
return true;
}
return false;
}
示例10: exec
public function exec($aliasPath)
{
$path = str_replace('/', DIRECTORY_SEPARATOR, \Yii::getAlias($aliasPath));
$this->migrationPath = dirname($path);
$this->db = Instance::ensure($this->db, Connection::className());
$this->getNewMigrations();
return $this->migrateUp(basename($path));
}
示例11: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::className());
if (is_string($this->cache)) {
$this->cache = Yii::$app->get($this->cache, false);
}
}
示例12: down
public function down()
{
$configs = array_merge($this->configs, ArrayHelper::getValue(Yii::$app->params, 'migration.rbac', []));
$this->db = Instance::ensure($configs['db'], Connection::className());
$this->dropTable($configs['assignmentTable']);
$this->dropTable($configs['itemChildTable']);
$this->dropTable($configs['itemTable']);
$this->dropTable($configs['ruleTable']);
}
示例13: actionDatabase
/**
* Database action is responsible for all database related stuff.
* Checking given database settings, writing them into a config file.
*
* (Step 3)
*/
public function actionDatabase()
{
$success = FALSE;
$errorMsg = '';
$config = Configuration::get();
$param = Configuration::getParam();
$form = new DatabaseForm();
if ($form->load(Yii::$app->request->post())) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($form);
}
if ($form->validate()) {
$dsn = "mysql:host=" . $form->hostname . ";dbname=" . $form->database;
// Create Test DB Connection
Yii::$app->set('db', ['class' => Connection::className(), 'dsn' => $dsn, 'username' => $form->username, 'password' => $form->password, 'charset' => 'utf8']);
try {
Yii::$app->db->open();
// Check DB Connection
if (InstallerModule::checkDbConnection()) {
// Write Config
$config['components']['db']['class'] = Connection::className();
$config['components']['db']['dsn'] = $dsn;
$config['components']['db']['username'] = $form->username;
$config['components']['db']['password'] = $form->password;
$config['components']['db']['charset'] = 'utf8';
// Write config for future use
$param['installer']['db']['installer_hostname'] = $form->hostname;
$param['installer']['db']['installer_database'] = $form->database;
$param['installer']['db']['installer_username'] = $form->username;
Configuration::set($config);
Configuration::setParam($param);
$success = TRUE;
return $this->redirect(Yii::$app->urlManager->createUrl('//installer/setup/mailer'));
} else {
$errorMsg = 'Incorrect configuration';
}
} catch (Exception $e) {
$errorMsg = $e->getMessage();
}
}
} else {
if (isset($param['installer']['db']['installer_hostname'])) {
$form->hostname = $param['installer']['db']['installer_hostname'];
}
if (isset($param['installer']['db']['installer_database'])) {
$form->database = $param['installer']['db']['installer_database'];
}
if (isset($param['installer']['db']['installer_username'])) {
$form->username = $param['installer']['db']['installer_username'];
}
}
return $this->render('database', ['model' => $form, 'success' => $success, 'errorMsg' => $errorMsg]);
}
示例14: init
/**
* @throws InvalidConfigException
*/
public function init()
{
parent::init();
if (empty($this->db)) {
throw new InvalidConfigException('UserConfig::db must be set.');
}
$this->db = Instance::ensure($this->db, Connection::className());
if ($this->cache !== null) {
$this->cache = Instance::ensure($this->cache, Cache::className());
}
}
示例15: beforeAction
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
* It checks the existence of the [[migrationPath]].
*
* @param \yii\base\Action $action the action to be executed.
*
* @return boolean whether the action should continue to be executed.
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if ($action->id !== 'create') {
$this->db = Instance::ensure($this->db, Connection::className());
}
return TRUE;
} else {
return FALSE;
}
}