简体   繁体   English

Symfony2安装在子目录中

[英]Symfony2 installing in a sub-directory

I know this question has been asked before, but for some reason, it's not working for me. 我知道之前曾有人问过这个问题,但由于某种原因,它对我不起作用。

I'm trying to install symfony2 in a subfolder (IE: http://www.mydomain.com/myapp ), however, I'm running into several issues: 我正在尝试在子文件夹(IE: http ://www.mydomain.com/myapp)中安装symfony2,但是我遇到了几个问题:

It looks like I have to modify ALL of my routes to point to this subpath, IE: 看来我必须修改所有路由以指向此子路径IE:

fos_user_group:
    resource: "@FOSUserBundle/Resources/config/routing/group.xml"
    prefix: /myapp/group

..which does do the job for routing. ..这确实完成了路由工作。

HOWEVER, no matter what, even though in the symfony docs, it states that assetic will determine the correct path( http://symfony.com/doc/current/book/templating.html#linking-to-assets ), it is still attempting to locate assets from the root domain, IE: 但是,无论如何,即使在symfony文档中,它指出资产将确定正确的路径( http://symfony.com/doc/current/book/templating.html#linking-to-assets ),仍尝试从IE的根域中查找资产:

http://www.mydomain.com/bundles/acmedemobundle/js/script.js

I have looked in basically every link on google for related issues, I've tried RewriteBase /myapp , RewriteBase /myapp/web , but all to no avail. 我已经在Google的每个链接中寻找了相关的问题,我尝试了RewriteBase /myappRewriteBase /myapp/web ,但都无济于事。

Can anyone help me out here? 有人可以帮我从这里出去吗? This seems insane that it is this difficult to properly route my URLs and assets to the subfolder. 正确地将我的URL和资产路由到子文件夹似乎很疯狂。 For portability sake (even if the asset issue is somehow resolved), shouldn't there be a way to do this WITHOUT modifying all of my routes? 出于可移植性考虑(即使资产问题已通过某种方式解决),是否应该有办法在不修改我所有路线的情况下做到这一点?

On a side note, I haven't yet attempted to try this on a unix server. 附带一提,我还没有尝试在UNIX服务器上尝试此操作。 Currently all testing is being done on wampserver. 当前,所有测试都在wampserver上进行。

You can set the base url in the router object, maybe that will fix your problem? 您可以在路由器对象中设置基本网址,也许可以解决您的问题?

$this->getContainer()->get('router')->getContext()->setBaseUrl('/myapp');

If you do that you should not have to prefix all your routes with the name of the subdirectory. 如果这样做,则不必在所有路由前面加上子目录的名称。

I don't know if this is still and issue for you but it may help someone else. 我不知道这是否仍然适合您,但可能会对其他人有所帮助。 I believe that you should alter your config.yml or config_dev.yml (depending on environment) 我认为您应该更改config.yml或config_dev.yml(取决于环境)

For the assets set this (see the "templating" section): 对于资产,请对此进行设置(请参见“模板”部分):

framework:
router:
    resource: "%kernel.root_dir%/config/routing_dev.yml"
    strict_requirements: true
profiler: { only_exceptions: false }
#set default asset root
templating:
    assets_base_urls: 
        http: [ /path/to/web ]
        ssl:  [ /path/to/web ]

Where /path/to/web is the parent folder of the bundle folder. 其中/ path / to / web是捆绑文件夹的父文件夹。

My solution to this on a local environment was adding the following code in app/config/config.yml 我在本地环境上的解决方案是在app/config/config.yml添加以下代码

framework:
    templating:
        assets_base_urls:
            http: "http://localhost/symfony_folder/"
            ssl: "http://localhost/symfony_folder/"

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

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