Dostajętaki o to komunikat:
Expected argument of type "string", "Makoso\BlogBundle\Form\CommentType" given
Nie wiem co jest nie tak dlaczego w ogóle to wywala błąd jak powinno chyba przyjmować obiekt?
CommentType.php
namespace Makoso\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Class CommentType
*/
class CommentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('author')
->add('content')
->add('submit', 'submit')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Makoso\BlogBundle\Entity\Comment'
));
}
public function getName()
{
return 'makoso_blogbundle_comment';
}
}
PostController.php
namespace Makoso\BlogBundle\Controller;
use Makoso\BlogBundle\Repository\PostRepository;
use Makoso\BlogBundle\Entity\Comment;
use Makoso\BlogBundle\Entity\Post;
use Makoso\BlogBundle\Form\CommentType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
class PostController extends Controller
{
/**
* @Route(
* "/czytaj/{id}",
* name="makoso_blog_post_show",
* requirements={
* "id" : "\d+"
* }
* )
* @Template()
*/
public function showAction(Request $request,$id)
{
$em = $this->getDoctrine()->getManager();
$post = $em->find('MakosoBlogBundle:Post', $id);
if (!$post) {
throw $this->createNotFoundException();
}
$commentForm = $this->createForm(new CommentType(), null, []);
$commentForm->handleRequest($request);
if ($commentForm->isSubmitted()) {
/** @var Comment $comment */
$comment = $commentForm->getData();
$comment->setPost($post);
$em->persist($comment);
$em->flush();
}
return
[
'post' => $post,
'comment_form' => $commentForm->createView()
];
}
}