Skip to content
Advertisement

Unable to create new answer in Symfony

I’m making a a app in Symfony. I get Entities Answer and Question which are related. I want to enable users to add the answer to the question but I’ve got the problem with getting question_id to AnswerEntity. Here it what I came up with: Answer Controller

JavaScript

AnswerForm:

JavaScript

and AnswerEntity

JavaScript

The error is: [enter image description here][1] [1]: https://i.stack.imgur.com/fYGpo.png

but I have a function getQuestion in AnswerEntity so why doesn’t it read that? It read the function setQuestion which is the same Entity.

Is there any chance to do it another way?

Also I’m adding part of my question template code where I get to create_answer

JavaScript

Advertisement

Answer

Why don’t you have the questionId in your route. I think it’s a mandatory data to know which question the users tries to answer to.

With a requestParam id in the route and a method param typed Question the ParamConverter can inject the right question in your controller method

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement