symfony3.0 插入数据库

来源:互联网 发布:多旅行商问题算法 编辑:程序博客网 时间:2024/05/29 14:54

一,
/**
* @ORM\Column(name=”report_id”, type=”integer”)
* @ORM\Id
* @ORM\GeneratedValue(strategy=”AUTO”)
*/
protected $reportId;

/**
* Set articleId
*
* @param integer articleId@returnArticleReport/publicfunctionsetArticleId(articleId)
{
this>articleId=articleId;

    return $this;}

previoushttps=request->request->get(‘previous_https’);
reason=request->request->get(‘reason’);
reportType=request->request->get(‘type’);
report=newArticleReport();report->setArticleId($articleId);

    $report->setReason($reason);    $report->setReportType($reportType);    if($this->getUser()){        $report->setUserId($this->getUser()->getUserId());    }else{

// 当天没做完先注销若是分享给其他用户举报走进这里
patterns=/\d+/;pregmatchall(patterns,previoushttps,arr);
// 拿到share_id
shareid=arr[0][0];
conn=this->getDoctrine()->getConnection();
shareUserId=conn->fetchColumn(“SELECT user_id FROM share_record WHERE share_id = shareid);report->setShareUserId(shareUserId);  
        }  
        try{  
            $this->entityManager->persist($report);  
            $this->entityManager->flush($report);  
            return new AjaxResponse();  
        }catch(\Exception
e){
return new AjaxErrorResponse(‘举报提交失败,请重试!’);
}
}
}

0 0