1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-08-13 16:54:00 -04:00

[add] preparing to poche a new link

This commit is contained in:
Nicolas Lœuillet 2013-11-27 14:10:31 +01:00
parent 5da399d98e
commit f0a5115a23
5 changed files with 49 additions and 2 deletions

View File

@ -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']);
});

View File

@ -1,6 +1,8 @@
<?php
use Poche\Model\Entry;
use Symfony\Component\HttpFoundation\Request;
$front = $app['controllers_factory'];
$front->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;

11
app/views/add.twig Normal file
View File

@ -0,0 +1,11 @@
{% extends layout %}
{% block content %}
<form action="#" method="post">
{{ form_widget(form) }}
<input type="submit" name="submit" />
</form>
<p><a href="/">back to home</a></p>
{% endblock %}

View File

@ -1,6 +1,6 @@
{% extends layout %}
{% block content %}
Poche v2<br/>
{{ entry.id }} - {{ entry.title }}
<p><a href="index.php/add">poche a new link</a></p>
{% endblock %}

View File

@ -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/" }