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 8144855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:29:27+00:00 2026-06-06T13:29:27+00:00

I am a Symfony2 newbie running into problems with edit-forms and doctrine. I seem

  • 0

I am a Symfony2 newbie running into problems with edit-forms and doctrine.

I seem to be getting a corrupt object from my database somehow.

This code works fine…

$FormDebug = new Link();
$FormDebug->setUrl('http://www.mysite.com');

$editForm = $this->createFormBuilder($FormDebug)
  ->add('url','url')
  ->add('description','text')
  ->getForm();

While this doesn’t…

$repository = $this->getDoctrine()->getRepository('HemekonomiLinksBundle:Link');
$user = $this->container->get('security.context')->getToken()->getUser();       

$userLink = $repository->findBy(
    array('id' => $id, 'user' => $user->getId())
);


$editForm = $this->createFormBuilder($userLink)
  ->add('url','url')
  ->add('description','text')
  ->getForm();

So I guess I am getting an object that the formbuilder doesn’t agree with..? No error message, just that I don’t get a form filled out with the actual values of the fetched object, but rather an empty form.

When I var_dump() the object returned from the DB I can see that the correct values are there (along with all the properties of the user object – is this what’s causing my problem? The object containing more variables than the form?). The reason that the user is in there is of course to sort out only those link rows from the DB belonging to this particular user.

UPDATE:
I added two var_dump()s here, first the kind of object I expected to retrieve from the DB (just an example to describe the object) second what is actually being retrieved, I can see that repository-find action returns an array instead of an object, but my object seems to be included… why I do not know…

What I expected

object(Company\LinksBundle\Entity\Link)#556 (4) { ["id":protected]=> NULL ["user":protected]=> NULL ["description":protected]=> NULL ["url":protected]=> string(25) "http://www.mysite.com" }

What DB returns

array(1) { [0]=> object(Company\LinksBundle\Entity\Link)#553 (4) { ["id":protected]=> int(9) ["user":protected]=> object(Company\UserBundle\Entity\User)#145 (19) { ["id":protected]=> int(3) ["username":protected]=> string(5) "user1" ["usernameCanonical":protected]=> string(5) "user1" ["email":protected]=> string(6) "1@1.se" ["emailCanonical":protected]=> string(6) "1@1.se" ["enabled":protected]=> bool(true) ["salt":protected]=> string(31) "oltkauxmgw000w8wgw84ckggg8sw880" ["password":protected]=> string(88) "AFKlCO774d/4D8DHD3P/sXYYApS32jzdLm5GlZEICnOq8xyKT/xVjbnAziMUadecN0yBlxiH5QZK09s5KJxbsA==" ["plainPassword":protected]=> NULL ["lastLogin":protected]=> object(DateTime)#149 (3) { ["date"]=> string(19) "2012-06-27 07:04:24" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Stockholm" } ["confirmationToken":protected]=> NULL ["passwordRequestedAt":protected]=> NULL ["groups":protected]=> NULL ["locked":protected]=> bool(false) ["expired":protected]=> bool(false) ["expiresAt":protected]=> NULL ["roles":protected]=> array(0) { } ["credentialsExpired":protected]=> bool(false) ["credentialsExpireAt":protected]=> NULL } ["description":protected]=> string(22) "Beskrivning av länken" ["url":protected]=> string(16) "http://testlink.se" } }

Is what happens here that the DB returns the actual link object, and the user object connected to it, and it will be my job to weed out the one of the two that I want?

If so, is there a way to, already in the repository->find to specify that although I WHERE on the user field in my find statement, I am not interested in SELECTing the user object, I only want what’s in the Links TABLE? (Link object in symfony2 terms, I guess…)?

  • 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-06T13:29:28+00:00Added an answer on June 6, 2026 at 1:29 pm

    OK,

    so after some more trial-and-error I found that my find-method was causing the problem. Apparently, the findBy(array) also returns an array, in order to get that single object for editing I have to do find($id), by which I loose the functionality of SELECTing only if the user is trying to edit his “own” link…

    I anyway found out that the way I was doing it (by comparing on the user name instead of ID) might not be the best way…

    If anyone has comments on that, feel free to point me in the right direction, otherwise I will do some trial-and-error and post a new thread if I can’t work it out.

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

Sidebar

Related Questions

Using Symfony2 and orm.yml files to map the entities into the database how can
Does symfony2 have simple button type(not submit or file) for forms? I looked there(http://symfony.com/doc/current/reference/forms/types.html)
I'm using Symfony2 Framework, and I want to update an entity with data from
Using Symfony2 and Doctrine ODM with MongoDB, I need to access the parent document
In Symfony2, how can I go about adding Doctrine's entity manager to a custom
I have multiple symfony2 applications which share common entities, but use different database settings.
When I cap deploy my Symfony2 project, then log into my server I see
I downloaded symfony2 and I am able to run it starting from app_dev.php. But
I have a problem with doctrine2 in symfony2 app with postgres database. I get
Recently I started a project in Symfony2 from the BETA version available on symfony.com

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.