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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题