/**
* Lists all user entities.
*
* @Route("/article/{id}/{title}", name="article")
* @Template()
*/
public function articleAction($id, $title) {
$em = $this->getDoctrine()->getManager();
$article = $em->getRepository('TryoneeArticleBundle:Article')->find($id);
if (!$article)
return $this->redirect($this->generateUrl('main'));
if ($article->getTitle() != str_replace('-', ' ', $title)) {
return $this->redirect($this->generateUrl('article', array('id' => $article->getId(), 'title' => str_replace(' ', '-', $article->getTitle()))));
}
$keywordarray = explode(',', $article->getKeyword());
$newview = $article->getTotalView() + 1;
$article->setTotalView($newview);
$em->persist($article);
$em->flush();
return array(
'article' => $article,
'id' => $id,
'keywords' => $keywordarray,
'view' => $newview
);
}
这是我的控制器代码,我希望从文件中获取数据库并增加视图。 但是这段代码显示出一种奇怪的行为,有时它会增加4次,2次和单次。
我错过了什么......?任何帮助表示赞赏