frosas/base-url-bundle

Sets the router default base URL. It is required when the router is used while not dealing with a request (like in the console).

Installs: 419

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

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

This package is auto-updated.

Last update: 2024-04-18 03:08:01 UTC


README

Notice this functionality is already available in Symfony since version 2.1

This Symfony2 bundle sets the router default base URL (which by default is http://localhost)

It is required when absolute URLs are generated while not dealing with a request (like when sending an email from a cron job).

Installation and configuration

  1. Require it

    $ composer require frosas/base-url-bundle:1.*@dev
  2. Register it in app/AppKernel.php

    $bundles = array(
        // ...
        new Frosas\BaseUrlBundle\FrosasBaseUrlBundle
    );
  3. Set the base URL. This is the recommended usage:

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

Troubleshooting

  • Controller tests fail when using generated URLs

    If you generate the URLs you test

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

    your tests can fail as the default Symfony test client expects the site to be in the root of the domain (like http://example.com). If your base URL has a path (like http://localhost/~user/my-site) you'll have to change it for you test environment.

    # app/config/config_test.yml
    frosas_base_url:
        base_url: http://localhost