Ejemplo n.º 1
0
 /**
  * @return bool If connection ok?
  */
 public function testConnection()
 {
     $config = SetupHelper::createDatabaseConfig($this->getAttributes());
     $result = false;
     try {
         /** @var \yii\db\Connection $dbComponent */
         $dbComponent = Yii::createObject($config);
         $dbComponent->open();
         $result = true;
     } catch (\Exception $e) {
         Yii::$app->session->setFlash('danger', Yii::t('setup', 'Database connection error:') . ' ' . $e->getMessage());
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function action3()
 {
     $dbForm = new DBForm();
     $connectionOk = false;
     if ($dbForm->load(Yii::$app->request->post()) && $dbForm->validate()) {
         if ($dbForm->testConnection()) {
             if (isset($_POST['test'])) {
                 $connectionOk = true;
                 Yii::$app->session->setFlash('success', Yii::t('setup', 'Database connection - ok'));
             }
             if (isset($_POST['save'])) {
                 $config = SetupHelper::createDatabaseConfig($dbForm->getAttributes());
                 if (SetupHelper::createDatabaseConfigFile($config) === true) {
                     return $this->render('4');
                 }
                 Yii::$app->session->setFlash('warning', Yii::t('setup', 'Unable to create db config file'));
             }
         }
     }
     return $this->render('3', ['model' => $dbForm, 'connectionOk' => $connectionOk]);
 }