2012-03-14 96 views

回答

2

創建一個新的評論對象,填充它的值,然後保存它。

$c = new Comment(); 
$c->fromArray($request->getParameter("comment")); 
$c->save(); 

這是最簡單的方法。但是,你應該使用一種形式,所以它也驗證:

$f = new CommentForm(); 
$f->bind($request->getParameter($f->getName())); 
if ($f->isValid()) { 
    $f->save(); 
} 

更多信息,請參見form framework documentation

相關問題