1

I have little problem, I have no idea what's wrong with my code :/

$ilosc = $_POST["ilosc"];

        $recipe = new Recipe();
        $em = $this->getDoctrine()->getManager();
        $repository = $this->getDoctrine()->getRepository('MainBundle:Recipe');

        $query = $repository->createQueryBuilder('p')->select('p.id')->where('p.nazwa = :nazwa AND p.adres = :adres')->setParameters(array('nazwa' => $_POST["nazwaprzepisu"], 'adres' => $_POST["adresprzepisu"]))->getQuery();
        $test = $query->getResult();
        $id = $test[0]['id'];


        $idprod = $_POST['idprod'];
        $iloscprod = $_POST['iloscprod'];


        for ($i = 0; $i < $ilosc; $i++)
        {
            $ingredient = new Ingredient();
            $repositorying = $this->getDoctrine()->getRepository('MainBundle:Ingredient');
            $query = $repositorying->createQueryBuilder('p')->select('p')->where('p.przepis_id = :id AND p.produkt_id = :idprod')->setParameters(array('id' => $id, 'idprod' => $idprod[$i]))->getQuery();
            $result = $query->getResult();

            if(!$result)
            {
                $ingredient->setProduktId($idprod[$i]);
                $ingredient->setPrzepisId($id);
                $ingredient->setIlosc($iloscprod[$i]);

            }
            else
            {
                $nowailosc = $result[0]['ilosc'] + $iloscprod[$i];
                $stareid = $result[0]['id'];

                echo "kokoko";

            }
            $em->persist($ingredient);
            $em->flush();   
        }

I have problem with those two lines:

$nowailosc = $result[0]['ilosc'] + $iloscprod[$i];
$stareid = $result[0]['id'];

I get an error: "Fatal error: Cannot use object of type My\MainBundle\Entity\Ingredient as array in". Somebody have idea what I am doing wrong?

1 Answer 1

1

Problem solved. I had to use:

$nowailosc = $result[0]->getIlosc() + $iloscprod[$i];
$stareid = $result[0]->getId();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.