如何在其他数据库上设置Symfony用户身份验证?

时间:2019-05-06 06:06:34

标签: authentication symfony4

我正在使用Symfony 4,并且想添加一个用户身份验证。我跟随documentation使用MakerBundle命令创建用户实体。但是由于我的网站上有一些不相关的应用程序,因此我希望此用户表具有通用性并存储在其自己的数据库中。在Laravel中,我可以通过在数据库配置文件中定义不同的db连接,然后指定要在迁移文件中使用的连接来实现。但是我找不到有关Symfony的任何文档。

我该怎么做?

更新详细信息:

MakerBundle命令“ make:user”创建了两个文件,一个用户实体和一个UserRepository文件。用户实体具有属性$id$username$password$roles

我正在使用phpmyadmin来管理数据库,我当前的应用程序处理模型,因此我的目标是拥有一个用于该应用程序的model_db和一个用于用户登录的site_user数据库。随着我日后向该站点添加更多应用程序,当site_user数据库处理所有数据库的身份验证时,我将为每个数据库创建一个单独的数据库。

运行命令php bin/console make:migration创建了一个迁移文件,该文件会将用户表添加到数据库中,但是我不知道如何修改它,以便将该表添加到site_user db中,而不是model_db中。

# migration file
final class Version20190506075410 extends AbstractMigration
{
    public function getDescription() : string
    {
        return '';
    }

    public function up(Schema $schema) : void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649F85E0677 (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
    }

    public function down(Schema $schema) : void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('DROP TABLE user');
    }
}

0 个答案:

没有答案
相关问题