Reputation: 1529
I am new to yii Framework now I want to pass value from Controller action to Ajax on Success and by getting the value I have store it in php variable . How to achieve this ?
My Controller Action :
public function actionNewrefList($id)
{
$model=new RefListModel();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['RefListModel']))
{
$model->attributes=$_POST['RefListModel'];
$model->crm_base_contact_id=$id;
if($model->save())
{
/** Here i need to send value of $model->crm_ref_list_id to Ajax Onsuccess **/
return;
}
}
}
My View Ajax:
echo CHTML::ajaxSubmitButton('Save', Yii::app()->createUrl('baseContact/NewrefList',array("id" => $base)),
array('success' => 'js:function(){
'))
Here I have to get the value passed from controller and store it in PHP Variable.
Upvotes: 1
Views: 6031
Reputation: 3435
if(isset($_POST['RefListModel']))
{
$model->attributes=$_POST['RefListModel'];
$model->crm_base_contact_id=$id;
if($model->save())
{
echo $model->crm_ref_list_id;
Yii::app()->end();
}
}
In view:
echo CHTML::ajaxSubmitButton('Save',
Yii::app()->createUrl('baseContact/NewrefList',
array("id" => $base)),
'success' => 'js:function(data){
alert(data);
}'))
Upvotes: 2