I was doing a simple update operation when this error occurred. The update operation is done but when I tried to get back to see the modification on the page I get this error below:
Warning: preg_match() expects parameter 2 to be string, object given
This is my Twig Code:
<form class="form-horizontal" method="post" action="{{ path('Update_comment',{'idc':comment.id}) }}">
<div class="control-group">
<label class="control-label" for="inputPassword">New Comment <sup>*</sup></label>
<div class="controls">
<textarea name="contenu" cols="2" rows="20"></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success">
<i class=" icon-pencil"></i>Edit
</button>
</div>
</div>
</form>
This is my Action's code:
public function UpdateCommentAction($idc){
$em = $this->getDoctrine()->getManager();
$cmt = $em->getRepository('MyAppUserBundle:PostComment')->find($idc);
$idPost=$cmt->getIdPost();
if ($cmt != null) {
if (isset($_POST['contenu'])) {
$cmt->setContenu($_POST['contenu']);
$em->flush();
}
}
return $this->redirectToRoute("get_view_post", array('id' => $idPost));
}
and these are my routing's configuration:
get_view_post:
path: /blog/get/one/post/{id}/
defaults: { _controller: "MyAppBlogBundle:Blog:getpost" }
Update_comment:
path: /blog/get/post/Comment/Update/View/{idc}
defaults: { _controller: "MyAppBlogBundle:Blog:UpdateComment" }
I don't know where is the problem, especially that the Updation operation is working.