Juice
Juice

Reputation: 3063

how to insert values into database using ajax in symfony1.4

in my project i want to add comments to each post. For inserting comments i am using ajax. since INSERT statements are not allowed in DQL. How can i insert comments using ajax. any one please help me. thanks in advance..

Upvotes: 0

Views: 619

Answers (1)

Maerlyn
Maerlyn

Reputation: 34107

Create a new comment object, fill it with values, then save it.

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

This is the easiest way. But you should be using a form, so it's also validated:

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

See the form framework documentation for more info.

Upvotes: 2

Related Questions