i have the follwoing code in the controller but the save is not working
[b] public function actionPostComment() {
$model = new SwComment();
$date = date('Y-m-d H:i:s');
$parent_id = 0;
if ($_REQUEST['comment'] == "") {
echo CJSON::encode(array(
'status' => 'error',
'error' => 'please enter some comment..'
));
} else {
$sw_id = $_REQUEST['id'];
$comments = $_REQUEST['comment'];
$model->date = $date;
$model->swid = $sw_id;
$model->parent_id = $parent_id;
$model->comments = $comments;
$model->user_id = 8;
if ($model->save()) {
echo CJSON::encode(array(
'cmnt' => $comments,
'status' => 'success',
));
} else {
echo CJSON::encode(array(
'cmnt' => 'data did not enter',
'status' => 'false',
));
}
}
Yii::app()->end();
}[/b]
i have the follwoing content in details.php
[b] <?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'job-form',
'enableAjaxValidation' => true,
));
?>
<div class="submenubar" >
<div class="imageicon"></div>
<div class="textfield" id="textfield">
<input id="q" class="uname_input" type="text" name="comment" title="Leave a Message" value="" />
</div>
</div>
<?php
echo CHtml::ajaxSubmitButton('post comment', $this->createUrl('software/postcomment', array('id' => $model->swid)), array(
'type' => 'POST',
'dataType' => 'json',
'success' => 'function(data)
{
if(data.status=="error")
{
alert(data.error);
}
else
alert(data.cmnt);
}',
));
$this->endWidget();
?>[/b]