From f0a5115a2385b9de29397c299dc0023793fc4ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 27 Nov 2013 14:10:31 +0100 Subject: [PATCH] [add] preparing to poche a new link --- app/app.php | 8 ++++++++ app/controllers/front.php | 23 +++++++++++++++++++++++ app/views/add.twig | 11 +++++++++++ app/views/index.twig | 2 +- composer.json | 7 ++++++- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 app/views/add.twig 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 %} + +
+ {{ form_widget(form) }} + + +
+

back to home

+{% 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
{{ entry.id }} - {{ entry.title }} +

poche a new link

{% endblock %} \ No newline at end of file diff --git a/composer.json b/composer.json index a8ef176..c42affb 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,12 @@ "symfony/twig-bridge": "~2.3", "knplabs/console-service-provider": "dev-master", "doctrine/dbal": "2.2.*", - "symfony/browser-kit": ">=2.3,<2.4-dev" + "symfony/browser-kit": ">=2.3,<2.4-dev", + "symfony/form": "~2.3", + "symfony/validator": "~2.3", + "symfony/config": "~2.3", + "symfony/translation": "~2.3", + "symfony/locale": "~2.3" }, "autoload": { "psr-0": { "Poche\\": "src/" }