frosas/base-url-bundle

此包已被弃用且不再维护。未建议替代包。

设置路由器的默认基础URL。当在不需要处理请求的情况下使用路由器时(如控制台)是必需的。

安装: 419

依赖项: 0

建议者: 0

安全: 0

星标: 4

关注者: 3

分叉: 0

开放问题: 1

类型:symfony-bundle

dev-master / 1.1.x-dev 2013-05-02 22:53 UTC

This package is auto-updated.

Last update: 2024-05-29 10:47:35 UTC


README

注意 此功能自2.1版本起已在Symfony中可用

此Symfony2扩展包设置路由器的默认基础URL(默认为https://

当在不处理请求的情况下生成绝对URL时(如从cron作业发送邮件)是必需的。

安装和配置

  1. 需要它

    $ composer require frosas/base-url-bundle:1.*@dev
  2. app/AppKernel.php中注册它

    $bundles = array(
        // ...
        new Frosas\BaseUrlBundle\FrosasBaseUrlBundle
    );
  3. 设置基础URL。这是推荐的使用方式

    # app/config/config.yml
    frosas_base_url:
        base_url: %base_url%
    
    # app/config/parameters.yml
    parameters:
        base_url: http://example.com
    

故障排除

  • 使用生成的URL进行控制器测试失败

    如果您生成要测试的URL

    $client = self::createClient();
    $profileUrl = $client->getContainer()->get('router')->generate('profile', array('id' => 123);
    $client->request('get', $profileUrl);

    您的测试可能会失败,因为默认的Symfony测试客户端期望网站位于域名根目录(如http://example.com)。如果您的基础URL包含路径(如https:///~user/my-site),您将需要更改您的测试环境中的路径。

    # app/config/config_test.yml
    frosas_base_url:
        base_url: https://