作者:手机用户2602925621 | 来源:互联网 | 2018-03-23 23:18
getDoctrine()->getEntityManager();
$query = $em->createQuery(
'SELECT m FROM DpDriveplusBundle:Messageboard m ORDER BY m.id DESC'
);
$comments = $query->getResult();
$count = count($comments);
return $this->render('DpDriveplusBundle:Message:index.html.twig', array('comments'=>$comments, 'count'=>$count));
}
public function ajaxAction()
{
$request = $this->getRequest();
$ret = '';
if ('POST' === $request->getMethod()) {
$name = $request->get('name');
$message = $request->get('message');
$ret = '姓名:'.$name.'
留言内容:'.$message.'
';
$comment = new Messageboard();
$comment->setName($name);
$comment->setMessage($message);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($comment);
$em->flush();
return new Response($ret);
}
}
}