【发布时间】:2015-06-16 17:08:29
【问题描述】:
我的问题
表单请求/POST 中的这两行有什么区别?
- $article->getComments() as $comment
- $form->get('Comments')->getData() as $comment
上下文
实体文章
class Article
{
private Comments
public function __construct() {
$this->Comments = new\Doctrine\Common\Collections\ArrayCollection()
}
public function getComments()
{
return $this->comments
}
表单请求
$article 是一个带有一些 cmets 的对象。
$form = $this->createForm(new ArticleType(), $article);
$request = $this->getRequest();
if($request->getMethode() == 'POST'){
$form->bind($request);
if($form->isValid()) {
$liste_comments = array();
$liste_comments_bis = array();
foreach($article->getComments() as $comment){
$liste_comments[] = $comment
}
foreach($form->get('comments')->getData() as $comment_bis){
$liste_comments_bis[] = $comment_bis
}
}
}
文章类型 添加文章内容并添加cmets集合
【问题讨论】:
标签: php forms symfony post doctrine