문제

I have problem with checkboxes. I'm sending list of checked checkbox to the controller which are values id's from database and it's working (array looks like Array ( [0] => 26 [1] => 27 [2] => 28 [3] => 29 )). But when i want to use these values from array to search row e.g

    $em = $this->getDoctrine()->getManager();
    $request = $this->get('request');
    $boxes=$request->request->get('checked');

    foreach($boxes as $key=> $value)
    {
        $query=$em->getRepository('AcmeStoreBundle:PrivateMessage')->findById($value);
        $query->setRecipientDelete(true);
        $em->flush();
    }`

i got error

Call to a member function setRecipientDelete() on a non-object

Have anyone idea what i'm doing wrong? I'm 100% sure all of ID's which i'm sending are in database.

도움이 되었습니까?

해결책

findById will most likely return a collection. try findOneById.

Further you may want to $em->persist($query); your object before flushing.

$repo = $em->getRepository('AcmeStoreBundle:PrivateMessage');

foreach($boxes as $key => $value)
{
    $message = $repo->findOneById($value);
    $message->setRecipientDelete(true);
    $em->persist($message);
}

$em->flush();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top