<commit_before># Creating a page

- create the route:

```yaml
home:
    pattern:  /
    defaults: { _controller: "AcmeBundle:Home:default" }
```

- create the controller:

```php
class HomeController extends Controller
{
    public function defaultAction(Request $request)
    {
        $page = new HomePage($request, $this->container);

        // POST -> action
        if ($request->isMethod('POST')) {
            $action = $request->get('action');

            if ($action == '') {
                throw new BadRequestHttpException("HTTP parameter 'action' must be given");
            }

            // Call action
            $page->$action();

            return $this->redirect($this->generateUrl('home'));
        }

        return $page->render();
    }
}
```

The `default` action catches all requests to the page.

For a `GET` request, it will display the page.
For a `POST` request, it will call an action on the page and then redirect to the page.

- create a page in a `Acme\AcmeBundle\Page` namespace:

```php
namespace Acme\AcmeBundle\Page;

class HomePage extends BasePage
{
    public function getTemplate()
    {
        return 'AcmeBundle:Home:page.html.twig';
    }
}
```

`getTemplate()` returns the template of your page.<commit_msg>Improved documentation<commit_after># Creating a page

- create the route:

```yaml
home:
    pattern:  /
    defaults: { _controller: "AcmeBundle:Home:default" }
```

- create the controller:

```php
class HomeController extends Controller
{
    public function defaultAction(Request $request)
    {
        $page = new HomePage($request, $this->container);

        // POST -> action
        if ($request->isMethod('POST')) {
            $action = $request->get('action');

            if ($action == '') {
                throw new BadRequestHttpException("HTTP parameter 'action' must be given");
            }

            // Call action
            $page->$action();

            return $this->redirect($this->generateUrl('home'));
        }

        return $page->render();
    }
}
```

The `default` action catches all requests to the page.

For a `GET` request, it will display the page.
For a `POST` request, it will call an action on the page and then redirect to the page.

- create a page in a `Acme\AcmeBundle\Page` namespace:

```php
namespace Acme\AcmeBundle\Page;

class HomePage extends BasePage
{
    protected $title = 'Hello!';

    public function getTemplate()
    {
        return 'AcmeBundle:Home:page.html.twig';
    }
}
```

`getTemplate()` returns the template of your page.

Every property is passed to the view:

```html
<h1>{{ title }}</h1>
<p>This is an example.</p>
```
{'fraction_non_alphanumeric': 0.13152950018789927, 'fraction_numerical': 0.000751597143930853, 'mean_word_length': 2.6267029972752045, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5952523', 'n_tokens_mistral': 787, 'n_tokens_neox': 749, 'n_words': 246}