duanmu2015 2019-04-05 02:11
浏览 27

使用多个实体管理器时出错500

I'm trying to work with multiple entity managers / connections on Symfony and Doctrine. The default em works perfectly, but my custom em don't.

Actually, I've seen the logs and the last thing that happens is the Doctrine Query. After that, I get a 500 error. And not the Symfony one.

I tried changing the directories structures with so many combinations, but no success. I think it's not related at all.

I tried changing doctrine.yaml configurations for the EM: I tried setting auto_mapping to true, changed "dir" to "dir: '%kernel.project_dir%/src/Entity/VL" and "dir: '%kernel.project_dir%/src/Entity'", tried to change "prefix: 'App\Entity\VL'" to "prefix: 'App\Entity'", and the Alias from "App" to "VL". No success also.

I tried some things on controller too, but I can't remember, so any tips are appreciated.

doctrine.yaml

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                # configure these for your database server
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.1.37'
                charset: utf8mb4
                default_table_options:
                    charset: utf8mb4
                    collate: utf8mb4_unicode_ci

                url: '%env(resolve:DATABASE_URL)%'

            vl:
                # configure these for your database server
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.1.37'
                charset: utf8mb4
                default_table_options:
                    charset: utf8mb4
                    collate: utf8mb4_unicode_ci

                url: '%env(resolve:VL_DATABASE_URL)%'


    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            default:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                connection: default
                auto_mapping: true
                mappings:
                    App:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Entity'
                        alias: App

            vl:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                connection: vl
                mappings:
                    App:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/VL'
                        prefix: 'App\Entity\VL'
                        alias: App

Controller (works perfectly without query)

use App\Entity\VL\Landingpage;

//...

/**
     * @Route("/{slug}", name="vl_landingpage", host="127.0.0.1")
     */
    public function landingpage($slug)
    {
        $landingpage = $this->getDoctrine()->getRepository(Landingpage::class, 'vl')->findOneBy(['slug' => $slug]);
        $content = $landingpage->getContent();
        return new Response($content);
    }

Landingpage Entity

namespace App\Entity\VL;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\VL\LandingpageRepository")
 */
class Landingpage
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
    //...
}

dev.log

[2019-04-04 22:57:39] request.INFO: Matched route "vl_landingpage". {"route":"vl_landingpage","route_parameters":{"_route":"vl_landingpage","_controller":"App\\Controller\\VendorLandingpageController::landingpage","slug":"teste"},"request_uri":"http://127.0.0.1:8000/teste","method":"GET"} []
[2019-04-04 22:57:39] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []
[2019-04-04 22:57:39] security.DEBUG: Checking support on guard authenticator. {"firewall_key":"main","authenticator":"App\\Security\\AppAuthenticator"} []
[2019-04-04 22:57:39] security.DEBUG: Guard authenticator does not support the request. {"firewall_key":"main","authenticator":"App\\Security\\AppAuthenticator"} []
[2019-04-04 22:57:39] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-04-04 22:57:40] doctrine.DEBUG: SELECT t0.id AS id_1, t0.name AS name_2, t0.email AS email_3, t0.responsable_name AS responsable_name_4, t0.telephone AS telephone_5, t0.whatsapp AS whatsapp_6, t0.address AS address_7, t0.social_medias AS social_medias_8, t0.creation_date AS creation_date_9, t0.last_modified AS last_modified_10, t0.slug AS slug_11, t12.id AS id_13, t12.content AS content_14, t12.additional_css AS additional_css_15, t12.custom_js AS custom_js_16, t12.landingpage_id AS landingpage_id_17 FROM landingpage t0 LEFT JOIN landingpage_content t12 ON t12.landingpage_id = t0.id WHERE t0.slug = ? LIMIT 1 ["teste"] []

I expect to get the "Landingpage" contents from the database (using the connection / em named "vl"), but I only get Error 500 after the query.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?