Skip to content

Instantly share code, notes, and snippets.

@mangelsnc
Last active January 19, 2018 16:06
Symfony Controller Normal
<?php
namespace App\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class BlogController extends AbstractController
{
/**
* @Route("/", defaults={"page": "1", "_format"="html"}, name="blog_index")
* @Method("GET")
*/
public function index(Request $request): Response
{
// Code to show all the posts
}
/**
* @Route("/posts/{slug}", name="blog_post")
* @Method("GET")
*/
public function postShow(Post $post): Response
{
// Code to show a single post
}
/**
* @Route("/comment/{postSlug}/new", name="comment_new")
* @Method("POST")
*/
public function commentNew(Request $request): Response
{
// Code to add a comment
}
/**
* @Route("/search", name="blog_search")
* @Method("GET")
*/
public function search(Request $request): Response
{
// Code to search
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment