Reputation: 83
the error is: The identifier id is missing for a query of Cocktails\RecipesBundle\Entity\Ingredient
So, the problem is that controller doesn't get the parameter ingredientId, I've tried many examples and tutorials but nothing helped. maybe there's some easy obvious mistake which I am missing? How could I pass parameters from ajax function to controller?
Upvotes: 0
Views: 752
Reputation: 904
Working code are
public function addIngredientToUserAction(Request $request) {
$usr = $this->getUser();
$id = $request->get('ingredient');
$ingredientEntity = $this->getDoctrine()->getRepository('CocktailsRecipesBundle:Ingredient')->find($id);
$usr->addIngredient($ingredientEntity);
return $this->render('CocktailsRecipesBundle:Default:menu.html.twig');
}
In your comment for previous answer you have made a mistake
$id = $request->get('id');
^^ - should be 'ingredient'
Upvotes: 0
Reputation: 16107
You're creating a new and empty Request object which obviously doesn't have the request information of the current request... it will be empty.
You can add a parameter to addIngredientToUser
called $request
and using type-hinting as Request $request
. This way Symfony2 will give you the actual request object of the current request populated with the correct request information.
Upvotes: 1