D3.js And Yii

I am trying to write a Yii action that is called from d3.js.

The javascript in d3.js is:


  d3.json(vr, function(error,j) {  // get the json object from yii.

   if (error) {showerror(error);return}    

   askquestions(...);

     });

   }



The page is rendered with Yii. I pass the variable vr in the view with:


   Yii::app()->clientScript->registerScript('uniqueid', 'var vr = "'.CHtml::encode($message->kiesprojectvragenurl).'";' ,CClientScript::POS_HEAD);

This generates the javascript code in the view:


<script type="text/javascript">

/*<![CDATA[*/

var vr = "/index.php?r=Kiesproject/kp&amp;projectid=9206";

/*]]>*/

</script>

KiesprojectController.php has the action:


public function actionKp($projectid)

{

 $data = some sql;

 return json_encode($data);

}

However, if I call the url from d3.js the debugger gives error 400 Bad request.

Calling the action with


$message->jsondata = $this->actionKp($message->projectid);  

renders the jsondata fine.

I do have two questions:

  1. Is this the correct way to get data into d3.js from Yii?

  2. What generates error 400? I can not find the error.

Thanks for your time.

Ar

I do have two answers.

  1. Is this the correct way to get data into d3.js from Yii?

No, this is translated javascript code. So the logic is completely wrong. Use yii classes and sessions.

  1. What generates error 400? I can not find the error.

What was lacking is a route to pass the parameters. Skip this when using sessions.