Skip to content

Instantly share code, notes, and snippets.

@nicosomb
Last active December 16, 2015 16:59
Show Gist options
  • Save nicosomb/5466955 to your computer and use it in GitHub Desktop.
Save nicosomb/5466955 to your computer and use it in GitHub Desktop.
problem with encoded url by a bookmarklet and routes in silex
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
));
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'db.options' => array(
'driver' => 'pdo_sqlite',
'path' => __DIR__.'/../storage/poche.sqlite',
),
));
/**
* example of generated url : http://silex.localhost/add/http%3A%2F%2Fsymfony.com%2F for http://symfony.com/
*/
$app->get('add/{url}', function($url) use ($app, $functions) {
// ...
// some stuff
// ...
return $app->redirect('/');
})->assert('url', '.+');
$app['debug'] = true;
$app->run();
@nicosomb
Copy link
Author

The bookmarklet :

javascript:void((function(){var%20url%20=%20location.href%20||%20url;window.open('http://silex.localhost/add/'+encodeURIComponent(url),'_self');})())

@funkyproject
Copy link

ça marche pour http://symfony.com sans encoder le lien

<?php
require_once __DIR__.'/../vendor/autoload.php'; 

use Symfony\Component\HttpFoundation\Request;
use Silex\Route;
use Silex\Controller;
$app = new Silex\Application(); 

$app['debug'] = true;

$route =  new Route('/add/{url}',array(),array('url'=>'.+'));
$route->setDefault('_controller', function($url) use ($app) {
    return $url;
});

$app['routes']->add('GET_add_url',$route);

$app->run(); 

@nicosomb
Copy link
Author

merci, je regarde

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment