diff --git a/app/app.php b/app/app.php index ad15a1a..5ea5e9c 100644 --- a/app/app.php +++ b/app/app.php @@ -2,6 +2,8 @@ use Knp\Provider\ConsoleServiceProvider; use Poche\Api\EntryApi; +use Silex\Provider\FormServiceProvider; + $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array( @@ -25,6 +27,12 @@ $app->register(new Silex\Provider\DoctrineServiceProvider(), array( ), )); +$app->register(new FormServiceProvider()); + +$app->register(new Silex\Provider\TranslationServiceProvider(), array( + 'translator.messages' => array(), +)); + $app['entry_api'] = $app->share(function ($app) { return new EntryApi($app['db']); }); diff --git a/app/controllers/front.php b/app/controllers/front.php index e03d7c5..f35019a 100644 --- a/app/controllers/front.php +++ b/app/controllers/front.php @@ -1,6 +1,8 @@ get('/', function () use ($app) { @@ -9,4 +11,25 @@ $front->get('/', function () use ($app) { return $app['twig']->render('index.twig', array('entry' => $entry)); }); +$front->match('/add', function (Request $request) use ($app) { + $data = array('url'); + + $form = $app['form.factory']->createBuilder('form', $data) + ->add('url') + ->getForm(); + + $form->handleRequest($request); + + if ($form->isValid()) { + $data = $form->getData(); + + // do something with the url + + return $app->redirect('/'); + } + + // display the form + return $app['twig']->render('add.twig', array('form' => $form->createView())); +}); + return $front; diff --git a/app/views/add.twig b/app/views/add.twig new file mode 100644 index 0000000..76bd0a4 --- /dev/null +++ b/app/views/add.twig @@ -0,0 +1,11 @@ +{% extends layout %} + +{% block content %} + +
+ +{% endblock %} \ No newline at end of file diff --git a/app/views/index.twig b/app/views/index.twig index 337aba0..6076b75 100644 --- a/app/views/index.twig +++ b/app/views/index.twig @@ -1,6 +1,6 @@ {% extends layout %} {% block content %} -Poche v2