[Facelift] Symfony2 versus Flat PHP (book/from_flat_php_to_symfony2.rst) #2374

Closed
weaverryan opened this Issue Mar 30, 2013 · 3 comments

Projects

None yet

4 participants

@weaverryan
Member

This ticket is about re-reading this document and giving it a facelift. No matter who you are, you have a role to play in this.

How this works:

If you read this document and find some changes, you can either comment here or (even better) create a pull request. After various people have reviewed this chapter, we'll close this issue.

What to do

Well, that depends on who you are :)

If you're newer to Symfony

Read the entry and code along with it.
a) Are there inaccuracies - code that doesn't work?
b) Are there parts that just don't understand very well?
c) Are there details that aren't explained enough?
d) Is there language that's confusing?
e) Did you fall asleep while reading it? If so, good morning! Why was it so boring?
f) Are there inconsistencies between sections?

If you know Symfony pretty darn well (or want a challenge)!

a) Are there inconsistencies between sections?
b) Do you spot anything that can be done better?
c) Are we following best practices?
d) Are there sections that are too advanced or details that should be moved into a new section to keep this readable?
e) Should some details here belong somewhere else? Like in the component documentation?
f) Are there places where we can link to other areas in the documentation to help the learner cross reference?

@antekresic

In "Add a Touch of Symfony2" section, we aren't adding just a touch, since the composer example adds Twig and Doctrine to the project. The example uses just the Http Foundation part of Symfony. Maybe we could add a note about this?

@stof
Member
stof commented Mar 30, 2013

Fighting against @weaverryan's lazyness, here is the link: http://symfony.com/doc/current/book/from_flat_php_to_symfony2.html 😄

@stof
Member
stof commented Mar 30, 2013
  • I think the section introducing the model should warn that this code has a drawback: it opens and closes the DB connection in the functions getting the data instead of reusing it.

  • The first example of the sample application in Symfony2 could be simplified regarding the Doctrine calls:

    // src/Acme/BlogBundle/Controller/BlogController.php
    namespace Acme\BlogBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    
    class BlogController extends Controller
    {
        public function listAction()
        {
            $posts = $this->getDoctrine()
                ->getRepository('AcmeBlogBundle:Post')
                ->findAll();
    
            return $this->render(
                'AcmeBlogBundle:Blog:list.html.php',
                array('posts' => $posts)
            );
        }
    
        public function showAction($id)
        {
            $post = $this->getDoctrine()
                ->getRepository('AcmeBlogBundle:Post')
                ->find($id)
            ;
    
            if (!$post) {
                // cause the 404 page not found to be displayed
                throw $this->createNotFoundException();
            }
    
            return $this->render(
                'AcmeBlogBundle:Blog:show.html.php',
                array('post' => $post)
            );
        }
    }

    Additionally, half of it could be removed when using SensioFrameworkExtraBundle. But I'm not sure it is appropriate in the first chapter (as the goal is too show that most work can be handled by Symfony already, it could though):

    // src/Acme/BlogBundle/Controller/BlogController.php
    namespace Acme\BlogBundle\Controller;
    
    use Acme\BlogBundle\Entity\Post;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    
    class BlogController extends Controller
    {
        public function listAction()
        {
            $posts = $this->getDoctrine()
                ->getRepository('AcmeBlogBundle:Post')
                ->findAll();
    
            return $this->render(
                'AcmeBlogBundle:Blog:list.html.php',
                array('posts' => $posts)
            );
        }
    
        public function showAction(Post $post)
        {
            return $this->render(
                'AcmeBlogBundle:Blog:show.html.php',
                array('post' => $post)
            );
        }
    }
  • the routing example is only showing the YAML format. Other formats should be added IMO (even the previous chapter is showing XML and PHP)

  • the front controller does not match the Symfony 2.1+ one (the dispatching of the terminate event is missing)

  • The last paragraph comparing PHP templates and Twig should mention that Twig is the recommended format in Symfony instead of just saying it is well-supported IMO

@wouterj wouterj closed this Dec 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment