Hi I just started a project with Symfony and I think I am doing something wrong. Right now I want to a create simple page with table and filters so I created controller for it.

```
/**
 * @Route("/")
 */
class HomeController extends Controller {

    public function index(Request $request) {
        //Form to add new documents
        $form = $this->newForm();
        $form->handleRequest($request);

        $user = $this->getDoctrine()->getRepository(User::class)->find($this->getUser());
        //Gets all user documents
        $files = $user->getDocuments();
        //Gets all categories
        $categories = $this->getDoctrine()->getRepository(Category::class)->findAll();

        //Adds new document to database
        if($form->isSubmitted() && $form->isValid()) {
            $article = $form->getData();
            $article->setUser($this->getUser());
            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($article);
            $entityManager->flush();
            return $this->redirectToRoute('index');
        }

        return $this->render('home/home.html.twig', [
            'files' => $files,
            'categories' => $categories,
            'form' => $form->createView(),
        ]);
    }
}

```

This controller just displays documents in table and categories in navigaton. So then to add category filters I just made new function:

```
/**
 * @Route("/{categoryId}")
 */
public function categories(request $request, $categoryId)
    {
        $form = $this->newForm();
        $form->handleRequest($request);

        $user = $this->getDoctrine()->getRepository(User::class)->find($this->getUser());
        $categories = $this->getDoctrine()->getRepository(Category::class)->findAll();

        $category = $this->getDoctrine()->getRepository(Category::class)->findOneBy(["id" => $categoryId]);
        $categoryFiles = $this->getDoctrine()->getRepository(Document::class)->categoryFiles($category, $user);

        if($form->isSubmitted() && $form->isValid()) {
            $article = $form->getData();
            $article->setUser($this->getUser());
            $entityManager = $this->getDoctrine()->getManager();
            $entityManager->persist($article);
            $entityManager->flush();
            return $this->redirectToRoute('index');
        }

        return $this->render('home/home.html.twig', [
            'files' => $categoryFiles,
            'categories' => $categories,
            'form' => $form->createView(),
        ]);
    }

```

Everything works, but I have to repeat same code for categories and forms in all of my functions. Thank you for your help.