简体   繁体   English

Symfony2缓存和参数

[英]Symfony2 cache and parameters

I have an odd app set up, multiple sub domains all pointing to the same Symfony2 install. 我设置了一个奇怪的应用程序,多个子域都指向同一Symfony2安装。

The subdomain simply changes a single parameter within the application so that different content is loaded. 子域只需更改应用程序内的单个参数,即可加载不同的内容。

This parameter is being cached however, so visiting a.site.com and then b.site.com makes A's content appear rather than B's. 但是,此参数已被缓存,因此访问a.site.com然后访问b.site.com会使A的内容出现,而不是B的内容出现。

Is there another approach I can use? 我可以使用另一种方法吗?

Is there a way I can add this parameter the cache's hash or something similar so that when the parameter changes within the app the content can change. 有没有一种方法可以添加此参数,缓存的哈希值或类似内容,以便在应用程序中更改参数时内容也可以更改。

I am using this method to pass the constant from the sub domain into the Symfony2 application 我正在使用此方法将常量从子域传递到Symfony2应用程序中

How to pass a PHP constant as service argument in Symfony 2? 如何在Symfony 2中将PHP常量作为服务参数传递?

You can use Symfony's Request Object to get the URL and parse that for the subdomain. 您可以使用Symfony的Request对象获取URL并解析该子域的URL。 Use that to create your configuration parameter because it won't be cached. 使用它来创建您的配置参数,因为它不会被缓存。

Like this: 像这样:

echo $request->getUri();

Symfony's API can be a great resource, but a bit hard to read. Symfony的API可能是很好的资源,但是有点难以阅读。 http://api.symfony.com/2.6/Symfony/Component/HttpFoundation/Request.html http://api.symfony.com/2.6/Symfony/Component/HttpFoundation/Request.html

I ended up writing a service to parse the host name, that service was then available within my Controllers. 我最终写了一个服务来解析主机名,该服务随后在我的控制器中可用。

class GameSystem {

    public function getGameSystemName()
    {
        $ar = explode(".", $_SERVER['HTTP_HOST']);
        $first = reset($ar);

        $game_system_short_name = strtolower($first);

        return $game_system_short_name;
    }
}

Initially I had tried to use the constant value set in each subdomain's index file. 最初,我尝试使用每个子域的索引文件中设置的常量值。 But this was failing and having some really odd effects. 但这是失败的,并产生了一些非常奇怪的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM