Uploading file for related entity I see that my code smells.  The first file is a controller, and createAction.  But I don't know where to delegate this.

BookController.php - Whole controller class

So this is most 'smelly' code to me:

public function createAction(Request $request) {
    $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();

    $book = new Book();

    $form = $this-&gt;createForm(new BookType($user-&gt;getId()), $book);

    $form-&gt;handleRequest($request);

    if($form-&gt;isValid()) {
        $book-&gt;upload();
        $em = $this-&gt;getDoctrine()-&gt;getManager();
        $em-&gt;persist($book);
        $em-&gt;flush();

        $covers = $request-&gt;files-&gt;get('covers');
        foreach ($covers as $cover) {
            $coverObj = new BookCover();
            $coverObj-&gt;setFile($cover);
            $coverObj-&gt;setBook($book);
            $coverObj-&gt;upload();

            $em-&gt;persist($coverObj);
        }
        $em-&gt;flush();
        return $this-&gt;redirect($this-&gt;generateUrl('matiit_book_homepage'));
    }

    return $this-&gt;render('MatiitBookBundle:Book:new.html.twig', ['form' =&gt; $form-&gt;createView()]);
}


Rest of files:


new.html.twig
Book.php
BookType.php
BookCover.php


Uploading in entities is the second thing which bothers me.

It would be nice to know what is worth testing here - I have no experience with tests so it would be very useful for me.
BookController.php

I don't see anything to change, the only thing which i could do different is the return line from 

 return $this-&gt;render('MatiitBookBundle:Book:new.html.twig', ['form' =&gt; $form-&gt;createView()]);


i would write something like this to make it more clear

return $this-&gt;render(
    'MatiitBookBundle:Book:new.html.twig', 
    [
        'form' =&gt; $form -&gt; createView()
    ]
);


So if one day you need to add another line you will just add a , and the code will still look good.

new.html.twig

Why var $file? Why this $? It remember me something which is related to jQuery... Do you really need this? I would just do var file or choose a more specific name. (no idea right now, file could be ok but what is book_file? a input type="file"?)

Book.php

You use documentation only to specify the type of the fields? You could start with add the documentation of the fields and document all methods (or at least public/protected methods)

I'm wrong or here the indentation is a bit messed up? Could be just a copy/paste bug, anyway from protected $category; it wil look like you start write an inner class. (same for the end of the file)

Fix it if it's in your code.

What is length? I'm not English so maybe i'm wrong but i don't think length is a great name for a Book class (without documentation it's more hard to understand what is it). 

It's the book pages? What about totalPages? It's the length (size) of the file in bytes? What about fileSize?

BookType.php

class BookType extends AbstractType


Why not call your class AbstractType as AbstractBookType?

AbstractType could sound as something which is related to variables type, not your class.

I know you use namespaces but i think it's important to make the name of something very clear.

Here you could add documentation too.

BookCover.php

It looks so similar to Book.php

Some methods are similar, maybe Book should have an instance of BookCover inside instead of recreate the methods from zero?

I need more info about it.

protected function getUploadRootDir()
{
   // the absolute directory path where uploaded
   // documents should be saved
   return __DIR__.'/../../../../../web/'.$this-&gt;getUploadDir();
}


I'm not a PHP expert, but what if one day you change the location? You should remember to edit this method inside BookCover and inside Book too! Can't you make it in a static field for the two classes?

And you should maintain the /../../../../../ to point in the new location!

Anyway my review is more about style than other.