0

Basically I create a form that uses multiple entity, and the result retrieved from this form I wish the stock in another table separated into BDD. I was told to make an insertion (or update) request in a repository and call it from the controller after checking the submitted data. But in this case there will be no persist or flush in this case since you do not save an object corresponding to an entity there will be no persist or flush something like that, but I arrive Not really have to do it.

That's why I want to store in another table:

enter image description here

When I validate my form, my result retrieved by my form is stocked here (id: 6)

this is my code :

public function testAction(Request $request ){
    $poste = new Poste();
    $formPoste = $this->get('form.factory')->create(PosteType::class, $poste );


    $historique = new Historique_employer();


    if ($request->isMethod('POST')&& $formPoste->handleRequest($request)->isValid()) {

        $historique->setPoste($request->request['poste_id']->getData());
        $historique->setCity($request->request['City']->getData());
        $historique->setEmployer($request->request['Employer']->getData());
        $historique->setTemps($request->request['Temps']->getData());


        dump($poste);die();

        $em = $this->getDoctrine()->getManager();
        $em->persist($poste);
        $em->persist($historique);
        $em->flush();
    }



    return $this->render(':stat:teste.html.twig', array(
        'poste' => $formPoste->createView(),
        'historique' => $historique,
        ));

}

and I would like store my data in this entity :

class Historique_employer 
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @var Poste
     * @ORM\OneToOne(targetEntity="Poste")
     */
    private $poste;


    /**
     * @var City
     * @ORM\OneToOne(targetEntity="City")
     */
    private $city;


    /**
     * @var Temps
     * @ORM\OneToOne(targetEntity="Temps")
     */
    private $temps;


    /**
     * @var Employer
     * @ORM\OneToOne(targetEntity="Employer")
     */
    private $employer;

but when i do all that I have this error message :

Cannot use object of type Symfony\Component\HttpFoundation\ParameterBag as array

1 Answer 1

1

Symfony 2.8 ParameterBag

you are accessing the request parameters like arrays use mixed get(string $key, mixed $default = null, bool $deep = false)

$historique->setPoste($request->request->get('poste_id'));

change the rest and you are good go.

Sign up to request clarification or add additional context in comments.

1 Comment

do you know how can i do that?

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.