# ¿How to do this in slim 3?

**URL:** <https://discourse.slimframework.com/t/how-to-do-this-in-slim-3/913>\
**Category:** Questions\
**Created:** [November 17, 2016, 4:25am UTC](https://discourse.slimframework.com/t/how-to-do-this-in-slim-3/913 "2016-11-17T04:25:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mateoagudelo](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mateoagudelo](https://discourse.slimframework.com/u/mateoagudelo)\
**Post date:** [November 17, 2016, 4:25am UTC](https://discourse.slimframework.com/t/how-to-do-this-in-slim-3/913/1 "2016-11-17T04:25:30Z")

</div>

```
$app->get('/paste/nuevo/', function() use ($app) {
	$app->render('crear.php');
});
$app->post('/paste/nuevo/', function() use ($app) {
	$request = $app->request;
	$nombre = $request->post('nombre');
	$contenido = $request->post('contenido');
	$url = $request->post('url');
	$conectar = mysqli_connect('localhost', 'root', '', 'paste');
	$insertar = mysqli_query($conectar, "insert into pastes set p_nombre='$nombre', p_contenido='$contenido', p_url='$url' ");
	$app->redirect('../nuevo/');
});

```

I only use version 2.6

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [November 19, 2016, 11:32pm UTC](https://discourse.slimframework.com/t/how-to-do-this-in-slim-3/913/2 "2016-11-19T23:32:33Z")

</div>

The code can be translated to Slim 3 as follows:

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

// Create app and register PhpView
$app = new \Slim\App([
    'view' => function ($container) {
        return new \Slim\Views\PhpRenderer( __DIR__. '/../views/');
    }
]);

$app->get('/paste/nuevo/', function($request, $response) {
    return $this->view->render($response, 'crear.php');
})->setName('paste_nuevo');

$app->post('/paste/nuevo/', function($request, $response) {
    $body = $request->getParsedBody();

    $nombre = $body['nombre'];
    $contenido = $body['contenido'];
    $url = $body['url'];

    // database insert left out

    return $response->withRedirect($this->router->pathFor('paste_nuevo'));
});

$app->run();

```

I have left out the database insertion. There is an example of working with databases in the tutorial (see links below).

Here are some links that you may find helpful:

- [Upgrade guide](http://www.slimframework.com/docs/start/upgrade.html) for migrating from Slim 2 to Slim 3
- [First application](http://www.slimframework.com/docs/tutorial/first-app.html): a tutorial that covers working with routes, forms and databases in Slim 3
- [Route names and pathFor](http://www.slimframework.com/docs/objects/router.html#route-names) for redirecting to a named route
- [Templates in Slim 3](http://www.slimframework.com/docs/features/templates.html): I have chosen PhpView templating in the example above, but you may want to look into Twig
