A
A
Anton Medvedev2012-08-26 19:46:11
symfony
Anton Medvedev, 2012-08-26 19:46:11

Where to store user settings?

Where to store user settings like title, database settings. What would users be able to edit them through the form on the site?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Antonov, 2012-08-26
@SAGAK

DB configuration in config. Everything else is in the database.

S
Sergey, 2012-08-27
Protko @Fesor

Let me ask you, why would you allow users to edit database connection settings?

V
Vampiro, 2012-08-28
@Vampiro

class YourService extends ContainerAware
{ 

  public function switchDatabase($dbName, $dbUser, $dbPass) 
  {
    $connection = $this->container->get(sprintf('doctrine.dbal.%s_connection', 'dynamic_conn'));
    $connection->close(); // for sure ;)

    $refConn = new \ReflectionObject($connection);
    $refParams = $refConn->getProperty('_params');
    $refParams->setAccessible('public'); //we have to change it for a moment

    $params = $refParams->getValue($connection);
    $params['dbname'] = $dbName;
    $params['user'] = $dbUser;
    $params['password'] = $dbPass;

    $refParams->setAccessible('private');
    $refParams->setValue($connection, $params);

    $this->container->get('doctrine')->resetEntityMamager('dynamic_manager'); // for sure (unless you like broken transactions)
  }
}

stackoverflow.com/questions/6409167/symfony-2-multiple-and-dynamic-database-connection
And do what you want!!.. (c)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question