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

  • Home
  • SEARCH
  • 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 8963357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:20:14+00:00 2026-06-15T16:20:14+00:00

I am developing a blog in Symfony2. I have two entities in doctrine: The

  • 0

I am developing a blog in Symfony2. I have two entities in doctrine:

  • The first one is called Articles contains a list with the articles of the blog: title,
    text, date and user, where the user is the author of the post.
  • The second one is Users and is actually the users provider. Contains the name, the email,
    etc.

I generate the CRUD of the Article entity with:

php app/console doctrine:generate:crud

I get the following updateAction in the controller file:

public function updateAction(Request $request, $id)
{
    $em = $this->getDoctrine()->getManager();        
    $entity = $em->getRepository('BlogBundle:Staticpage')->find($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Staticpage entity.');
    }

    $deleteForm = $this->createDeleteForm($id);
    $editForm = $this->createForm(new EditStaticPageType(), $entity);
    $editForm->bind($request);

    if ($editForm->isValid()) {

        $em->persist($entity);            
        $em->flush();

        return $this->redirect($this->generateUrl('static_edit', array('id' => $id)));
    }

    return $this->render('BlogBundle:StaticsManagement:edit.html.twig', array(
        'entity'      => $entity,
        'edit_form'   => $editForm->createView(),
    ));
}

When I open the form to create a new article or edit an existing one, a box that contains the users of my User entity is displayed, so I can select one of them, since both tables are linked in the Entity with the ManyToOne annotation. However, I don’t want to select any user. I’d like to write in the Articles table the name of the user (the ID actually, since they are both linked) that is already logged in, and remove the list of the available users.

I already set up the security environment and it works properly, so this code will be always executed only if an user is logged in. I guess I have to edit the updateAction method, but I don’t know how.

  • 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-06-15T16:20:15+00:00Added an answer on June 15, 2026 at 4:20 pm

    First of all, if you are still learning Symfony, I would suggest not to use any CRUD generator. Better doing things manually at the first time, than use some sort of helper. Anyways, if I understand your question, you should set the current logged user as the article user:

    // Get logged user and set it as article user
    $loggedUser = $this->get('security.context')->getToken()->getUser();
    $entity->setUser($loggedUser);
    
    // Create edit form
    $editForm = $this->createForm(new EditStaticPageType(), $entity);
    
    // Bind the request if POST
    if('POST' === $request->getMethod()) {
        $editForm->bind($request);
    }
    
    // GET or invalid POST form
    if('GET' === $request->getMethod() || !$editForm->isValid()) {
        return $this->render('BlogBundle:StaticsManagement:edit.html.twig', array(
            'entity'      => $entity,
            'edit_form'   => $editForm->createView(),
        ));
    }
    
    // POST with valid form so persist
    $em->persist($entity);            
    $em->flush();
    

    Then remove the user field from the article edit form.

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

Sidebar

Related Questions

I am developing a blog site in asp.net 3.5 with C#. I have written
I am developing one Blog Website and I was wondering how to save the
i have an issue with the theme i am developing for my blog (
I'm developing a blog hosting service, and blog articles can be reached via URLs
hello im developing a blog right now... but i don't have idea how to
I am developing an app based on the programming joke blog I have created.
I started developing one Blog Website based on Hibernate and Struts. I was wondering
I'm starting developing with cocos2d-x for Android phones. I have followed these two tutorials
I'm developing blog speaker app. I wanna pause the audio when bluetooth is disabled
Background I am developing my blog application in Cake PHP. I aim to provide

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.