我是一个Symfony2新手遇到编辑形式和教条的问题。symfony2编辑表单与原则问题
我似乎从某种程度上从我的数据库中获取了一个损坏的对象。
此代码工作正常...
$FormDebug = new Link();
$FormDebug->setUrl('http://www.mysite.com');
$editForm = $this->createFormBuilder($FormDebug)
->add('url','url')
->add('description','text')
->getForm();
虽然这并不...
$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();
所以我想我得到一个对象,该formbuilder不同意。 。?没有错误消息,只是我没有得到一个表格填充了取出的对象的实际值,而是一个空的表单。
当我var_dump()从数据库返回的对象我可以看到正确的值在那里(以及用户对象的所有属性 - 这是什么导致我的问题吗?包含更多变量的对象比形式?)。用户在那里的原因当然是只从属于这个特定用户的数据库中挑选那些链接行。
更新: 我在这里添加了两个var_dump(),首先是我期望从数据库中检索的对象类型(只是描述对象的示例)第二个实际检索的对象,我可以看到,找到行动返回一个数组,而不是一个对象,但我的目标似乎包括...为什么我不知道...
我预计
object(Company\LinksBundle\Entity\Link)#556 (4) { ["id":protected]=> NULL ["user":protected]=> NULL ["description":protected]=> NULL ["url":protected]=> string(25) "http://www.mysite.com" }
DB返回什么
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) "[email protected]" ["emailCanonical":protected]=> string(6) "[email protected]" ["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" } }
这里发生的事情是,DB返回实际的链接对象以及与之相关的用户对象,我的工作是去除我想要的两个之一?
如果是这样,有没有办法,已经在存储库 - >查找以指定,虽然我在我的查找语句中的用户字段WHERE,我不感兴趣SELECT的用户对象,我只想要什么是在链接表? (用symfony2术语来说,链接对象,我猜...)?