Hi, I want to create a record in my DB with information from a form, i want to send it via AJAX
Here’s my view
<?php
/* @var $this UserController */
/* @var $model User */
//registering jQuery
Yii::app()->clientScript->registerCoreScript('jquery');
?>
<h1>User: <?php echo $model->username; ?></h1>
<h2>Entries</h2>
<ul>
<?php foreach($model->entries as $entry):?>
<div class="view">
<li class="entries"><h2> <?php echo $entry['title']; ?> </h2></li>
<li class="entries"><?php echo $entry['content']; ?></li><br/>
<li class="entries">Created on <?php echo date("d M - g:i A ",strtotime($entry['creation_date'])); ?></li><br/>
</div>
<?php endforeach; ?>
</ul>
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'sidebar')); ?>
<h1>Tweet Feed</h1>
<ul>
<?php $form=$this->beginWidget('CActiveForm', array('id'=>'hide-tweet',)); ?>
<?php $i=1; foreach($tweets as $tweet):?>
<div id="tw-<?php echo $i; ?>">
<h1><?php echo $tweet->id_str; ?></h1>
<div class="view">
<li class="entries"><?php echo '<b>'.$tweet->user->name.'</b> @'.$tweet->user->screen_name.' '.date("d M",strtotime($tweet->created_at)); ?></li><br/>
<li class="entries"><?php echo $tweet->text; ?></li>
<?php if($model->usr_id == Yii::app()->user->Id):?>
<br/><li class="entries">
<?php echo CHtml::ajaxLink(
'Click',
array('tweet/create'),
array(
'update'=>'#content',
'type'=>'POST',
'dataType'=>'json',
'data'=>array(
'tw_tweet_id'=>$tweet->id_str,
'tw_author'=>$model->usr_id,
'tw_name'=>$tweet->user->name,
'tw_creation_date'=>$tweet->created_at,
'tw_content'=>$tweet->text,
),
));
?>
</li>
<?php endif; ?>
</div>
</div>
<?php $i++; endforeach; ?>
<?php $this->endWidget(); ?>
</ul>
<?php $this->endWidget();?>
And in my tweet controller in the actionCreate function I have the following
public function actionCreate()
{
$model=new Tweet;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Tweet']))
{
echo "arrived at controller!!!";
var_dump($_POST['Tweet']);
//$model->attributes=$_POST['Tweet'];
//if($model->save())
//$this->redirect(array('view','id'=>$model->tw_id));
}
/*$this->render('create',array(
'model'=>$model,
));*/
}
When I click on the link it the POST return a 200 OK status but neither the echo and the var_dump show in my #content, I think I’m doing it wrong, can anyone please give some clearance in this matter, at least I want to be clear that the POST is working, having that I think I can do the rest.