我是Yii的新手。我有一個JavaScript變量。該ID必須傳遞給控制器和相應的視圖。在訪問控制器中的JS變量時遇到問題。請幫幫我。如果JS變量被傳遞,我將如何檢查傳入的變量。在此先感謝,將JS變量傳遞給Yii中的控制器和視圖
我從那裏JS變量(ID)是通過視圖:
<div style="float:left;padding-left:20px;">
<?php echo $form->labelEx($model,'host_customer_id'); ?>
<?php
echo $form->textField($model,'host_customer_id',array('style'=>'width:420px;'));
$this->widget('ext.select2.ESelect2', array(
'selector' => '#NimsoftHost_host_customer_id',
'options' => array(
'allowClear'=>false,
'placeholder' => 'Search Other Customers',
'minimumInputLength' => 3,
'quietMillis'=>100,
'ajax' => array(
'url' => Yii::app()->createUrl('Nimsoft/customers'),
'dataType' => 'jsonp',
'data' => 'js: function(term,page) {
return {
q: term,
//ctype: $("#itsmIncidents_cloudcustomer input:radio:checked").val(),
page_limit: 10,
};
}',
'results' => 'js: function(data,page){
return {results: data.details};
}',
),
'formatResult' => 'js:function(data){
return data.name;
}',
'formatSelection' => 'js: function(data) {
return data.name;
}',
),
));
?>
<div style="float:right;padding-left:10px;">
<?php
echo CHtml::link('view details', array('/Nimsoft/ciLink'), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size",height:500, align: "center" })',
'class'=>'btn btn-block btn-success',
'style'=>'width:100px;display:none;',
'id'=>'customer_details_pop',
));
?>
</div>
</div>
<?php $this->endWidget();?>
<script>
$("#NimsoftHost_host_customer_id").on("change", function(e) {
<?php echo CHtml::ajax(array(
'url'=>array('Nimsoft/loadCustType'),
'data'=> "js:{'NimsoftHost[host_customer_id]':e.val}",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
// enable customer link
$('#customer_details_pop').css('display','block');
$('#customer_details_pop').attr('href', 'Nimsoft/details/'+data.customerid);
} ",
))?>;
})
</script>
這裏我傳遞data.customerid。我想知道這個價值去控制器或不。如果是這樣,如何在我的視圖中打印(details.php)。
我的控制器動作:
public function actionDetails()
{
$this->render('details');
}
dat URL中的a.customerid將是查詢字符串而不是會話變量。你知道urlManager嗎? – synapze
我已更改我的代碼,請現在說 – user3318138