Symfony dynamic database credentials

Is it possible to make a input to set database user/password in Symfony at start-up of the application (like phpMyAdmin) ?

I want that my application do like this :

  • Welcome page (only html, no database connection with just input for db username/password (like phpMyAdmin))
  • User set username/password on inputs and click ok button => the values can be set into Request/post or Session in the controller by example
  • Symfony connect database to all application and redirect user to ‘app_index’ route

Is it possible to do it with Symphony 5 ?

Here my controller action:

public function database_login(Request $request, Connection $connection): Response
  {
    if ($request->isMethod('POST') && $request->request->has('dbpass')) {
      $dbpass = $request->request->get('dbpass');
      $params = $connection->getParams();
      $params['password'] = $dbpass;

      $connection->__construct($params, $connection->getDriver(), $connection->getConfiguration(), $connection->getEventManager());
      $connection->connect();
      return $this->redirectToRoute('app_index');
    }
    return new Response(
      '<form method="post">
        <input type="password" name="dbpass">
        <button type="submit">OK</button>
      </form>'
    );
  }

The new connection work’s fine but it lost after redirecToRoute() function.

Can you help me ?

Thanks

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *