Skip to content

Instantly share code, notes, and snippets.

@reinier
Forked from bobdenotter/composer.json
Created February 6, 2013 17:14
Show Gist options
  • Save reinier/4724125 to your computer and use it in GitHub Desktop.
Save reinier/4724125 to your computer and use it in GitHub Desktop.
{
"require": {
"silex/silex": "1.0.*@dev"
}
}
<?php
namespace Foo;
use Silex;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Bar implements ControllerProviderInterface
{
public function connect(Silex\Application $app)
{
$ctr = $app['controllers_factory'];
$ctr->match("/test", array($this, 'dothis'));
$ctr->match('/hello/{name}', array($this, 'hello'));
return $ctr;
}
public function dothis(Request $request, Silex\Application $app)
{
return 'Het werkt, naam is ' . $app['naam'];
}
public function hello(Silex\Application $app, $name) {
return 'Hello '.$name.'!';
}
}
<?php
require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/foobar.php';
$app = new Silex\Application();
$app['debug'] = true;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
// Even een 'naam' zetten, om te testen dat in je eigen controllers de $app
// nog beschikbaar is:
$app['naam'] = "pompidom";
/*
ROUTE THINGS
*/
$app->get('/', function () use ($app) {
return $app->redirect('/hello/Reinier');
});
$app->mount('', new Foo\Bar());
$app->run();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment