Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6383207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:37:13+00:00 2026-05-25T02:37:13+00:00

I am learning how to make a basic Blog in Symfony2 and have come

  • 0

I am learning how to make a basic Blog in Symfony2 and have come to a standstill when it comes to adding the comment system.

So far I can view the blog entries fine. Under a single blog post I am using Twig to render a form directly from a Controller:

{% render "PaulDemoBundle:Default:addComment" with { 'id': blog_entry.id } %}

As you can see I am populating the ID with the Id of the blog being viewed, in order to allow me to correctly attach the comment to the blog entry.

Below is the Action in my Controller:

public function addCommentAction(Request $request, $id)
{
    $add_comment = new Comment();
    $add_comment->setBlogId($id);

    $form = $this->createFormBuilder($add_comment)
            ->add('blog_id', 'hidden')
            ->add('author', 'text')
            ->add('comment', 'textarea')
            ->getForm();

    if ($request->getMethod() == 'POST') {
        $form->bindRequest($request);

        if ($form->isValid()) {
            $comment = $form->getData();
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($comment);
            $em->flush();

            return $this->redirect($this->generateUrl('_index'));
        }
    }

    return $this->render('PaulDemoBundle:Default:add_comment.html.twig', array('form' => $form->createView(), 'id' => $id));
}

here you can see that the Controller can pickup the Request data and the blog_id ($id). The form is generated with a hidden field that holds the blog_id.

Viewing the form HTML source, you get this:

<form action="/Symfony/web/app_dev.php/add_comment/3" method="post" >

<div id="form">
<input type="hidden" id="form__token" name="form[_token]" value="d4adb511709259d0df921a0a1b969cee0df83630" />
<input type="hidden" id="form_blog_id" name="form[blog_id]" value="3" />
<div><label for="form_author" class=" required">Author</label><input type="text" id="form_author" name="form[author]" required="required" value="" /></div>
<div><label for="form_comment" class=" required">Comment</label><textarea id="form_comment" name="form[comment]" required="required"></textarea></div></div>
<input type="submit" />

Again, you can see that the blog_id has been passed through (3).

Now, filling in the Author and Comment and hitting Submit, I get an error. It seems to think the blog_id is NULL. I have done a var_dump (and commented out the persist stuff) and the form request data shows that the blog_id is set to 3.

I even typecast $id to (int) as the form data shows it as a string (this shouldnt be a problem as it should be made an INT when it is persisted to the DB.

Can anyone see the problem?

Basically I have a M:1 Comment:Blog relationship and I need to somehow tell the application what blog is being viewed and pass along the ID (which I am doing atm, but it’s broken ofc!)

edit: the var_dump:

object(Paul\DemoBundle\Entity\Comment)#67 (6) { 
["id":"Paul\DemoBundle\Entity\Comment":private]=> NULL 
["blog_id":"Paul\DemoBundle\Entity\Comment":private]=> string(1) "3"
["blog":"Paul\DemoBundle\Entity\Comment":private]=> NULL 
["author":"Paul\DemoBundle\Entity\Comment":private]=> string(8) "Mr Jones" 
["comment":"Paul\DemoBundle\Entity\Comment":private]=> string(4) "test"
["created":"Paul\DemoBundle\Entity\Comment":private]=> NULL } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:37:13+00:00Added an answer on May 25, 2026 at 2:37 am

    Finally got it figured out. Just had to get the blog entry via GetRepository and use that to link the comment and blog together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small RIA that I built as a learning/make-my-life-easier project that uses
To make story short, i'm building self-learning banner management system. Users will be able
So I've been learning C++ and SDL to make some basic 2d games. I
I'm learning programming and I've wanted to make some basic data structures. I tried
I am just learning how to make basic stuff with a WebMatrix download, with
I'm learning J and starting with something basic; adding the multiples of 3 and
I'm just learning classes so I'm trying something basic. I have a class called
So I am currently learning C++ and decided to make a program that tests
I am learning GDI+ and I am trying to make a display window with
I'm a student learning PHP. I basically make the stuff work, but never wondered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.