1

I get list from my javascript function.Now i have to pass the list into the controller and access that list in my controller .I don't want to show the passed parameters in my url.How can this be done?

My java script code is:

    <script type="text/javascript" language="JavaScript">
      function act()
      { 
     var idList = $.fn.yiiGridView.getChecked("marketing-grid", "selectedIds");
     if(idList!="")
         {

  var parIdList = $.param({ 'idList': idList });
               window.location.href= '<?php echo Yii::app()->createUrl('marketing/composeMail'); ?>'+ '?'+parIdList;

           }
            else
             {
              alert("Please select row to Mail.");
                 }
              }
          </script> 

My controller code is:

 public function actionComposeMail()
{   
    $model=new Reply;
    $model->scenario = 'compose';
    $this->render('_compose',array('model'=>$model,//'model1'=>$modelMarket));
}

I have to pass idList in my controller and fetch that list in my function actionComposeMail().

1 Answer 1

2

In the view:

    <script type="text/javascript" language="JavaScript">
        function act() {
            var idList = $.fn.yiiGridView.getChecked("marketing-grid", "selectedIds");
            if (idList != "") {
                var url = '<?php echo $this->createUrl("marketing/composeMail"); ?>';
                var parIdList = $.param({ 'idList': idList });
                window.open(url+'?'+parIdList);
            } else {
                alert("Please select row to Mail.");
            }
        }
    </script>

In the controller:

public function actionComposeMail($idList)
{   
    // or $idList = Yii::app()->request->getQuery('idList');

    $model=new Reply;
    $model->scenario = 'compose';
    $this->render('_compose',array('model'=>$model,//'model1'=>$modelMarket));
}
Sign up to request clarification or add additional context in comments.

1 Comment

I tried your answer but but in url the passed list also adds up and doesnot recognise the composeMail method. Error appears : " Error 400 occurred Your request is invalid."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.