This bundle provides a service and twig extension for getting short urls like http://your.host/~short
Using the vendors script
Add the following lines in your deps file:
[BumzShortUrlBundle]
git=git://github.com/biozshock/ShortUrlBundle.git
target=bundles/Bumz/ShortUrlBundle
Run the vendors script:
$ php bin/vendors install
Using Git submodule
$ git submodule add git://github.com/biozshock/ShortUrlBundle.git vendor/bundles/Bumz/ShortUrlBundle
<?php
// app/autoload.php
$loader->registerNamespaces(array(
'Bumz' => __DIR__.'/../vendor/bundles',
// your other namespaces
));
<?php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Bumz\ShortUrlBundle\BumzShortUrlBundle(),
// ...
);
}
# /app/config/routing.yml
BumzShortUrlBundle:
resource: "@BumzShortUrlBundle/Resources/config/routing.yml"
prefix: /
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class UsersController extends Controller
{
public function getUserProfileShortAction()
{
...
$longUrl = $this->get('bumz_short_url.shortener')->shorten('http://example.com');
// $longUrl = '/~ShE'
...
}
}
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class UsersController extends Controller
{
public function getUserProfileShortAction()
{
...
$shortUrl = 'aUty';
$longUrl = $this->get('bumz_short_url.shortener')->getLong($shortUrl);
// $longUrl = 'http://example.com'
...
}
}
{{ 'http://example.com' | shortenUrl }}
{# this will output something like /~ShE #}