按主机拆分路由配置文件

问题描述 投票:0回答:1

我有这个routing.yml

backend_routes:
    resource: "%kernel.root_dir%/config/routing_backend.yml"
    host: "backend.com"

frontend_routes:
    resource: "%kernel.root_dir%/config/routing_frontend.yml"
    host: "frontend.com"

但是路由知道 %kernel.root_dir% 参数。我如何将其参数设置为routing.yml?

php routes symfony-2.3
1个回答
0
投票

也许我错了,但据我所知,您不需要设置 %kernel.root_dir% 参数,因为它在项目文件夹中的其他位置设置并且已经知道。在文件

YourProject\app\bootstrap.php.cache
中,您有

protected function getKernelParameters()
    {
        $bundles = array();
        foreach ($this->bundles as $name => $bundle) {
            $bundles[$name] = get_class($bundle);
        }
        return array_merge(
            array(
                'kernel.root_dir'        => $this->rootDir,
                'kernel.environment'     => $this->environment,
                'kernel.debug'           => $this->debug,
                'kernel.name'            => $this->name,
                'kernel.cache_dir'       => $this->getCacheDir(),
                'kernel.logs_dir'        => $this->getLogDir(),
                'kernel.bundles'         => $bundles,
                'kernel.charset'         => $this->getCharset(),
                'kernel.container_class' => $this->getContainerClass(),
            ),
            $this->getEnvParameters()
        );
    }

如果您在项目中找到字符串“kernel.root_dir”(例如使用 Notepad++),您会发现在默认值和第三方包中很多地方都设置了此参数。

不过,一般来说,如果您想设置参数值,您应该找到文件

YourProject\app\config\parameters.yml
(如果您选择 yml 作为捆绑包配置格式)。在那里添加不带 %% 的密钥及其值。

parameters:
    my.param: 25

如果您的配置是在 xml 中完成的,请使用

<parameters>
    <parameter key="my.param">25</parameter>
</parameters>

你就完成了。

© www.soinside.com 2019 - 2024. All rights reserved.