简体   繁体   English

Yii CJuiAutoComplete-在php中将用户选择的值存储到DB的最简单方法?

[英]Yii CJuiAutoComplete - Easiest way to store user selected value to DB in php?

I am new with Yii and JQuery... I am using Yii CJuiAutoComplete widget and everything is working in well... but whats the easiest way for me to store the "selected value" by the user here ( "$("#selectedSchool").text(ui.item.value)" ) into PHP variable so I can insert that value into my DB 我是Yii和JQuery的新手...我正在使用Yii CJuiAutoComplete小部件,并且一切工作都很好...但是,对于我来说,在这里存储用户“选择的值”的最简单方法是什么(“ $(”#selectedSchool “).text(ui.item.value)”)放入PHP变量中,这样我就可以将该值插入到我的数据库中

Whats the best easiest way to accomplish this in Yii? 在Yii中实现此目标的最佳方法是什么? How do I store jquery value into PHP variable with respect to Yii??... please advise ..A quick example will help I am stuck thanks 如何将有关Yii的jquery值存储到PHP变量中?......请告知..一个简单的示例将帮助我解决问题,谢谢

 <?php
 $this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'name'=>'school',
'sourceUrl'=>Yii::app()->createUrl('items/getPageTitles'),

 'options'=>array(
 'showAnim'=>'fold',
 'minLength'=>'2',
 'type'=>'get',
 'select'=>'js:function(event, ui) {

  //How do i store this below in Yii into PHP (so I can insert into DB)??
  $("#selectedSchool").text(ui.item.value);

 }'


),
'htmlOptions'=>array(
    'style'=>'width: 500px;',
    'placeholder' => 'Type your School'
   ),

 ));
 ?>

 <span id="selectedSchool"></span>

zii.widgets.jui.CJuiAutoComplete use http://jqueryui.com/autocomplete/ . zii.widgets.jui.CJuiAutoComplete使用http://jqueryui.com/autocomplete/ Therefore, source should have pattern: [ { "label": "Choice1", "value": "value1" }, ... ] 因此,源应具有以下模式:[{“ label”:“ Choice1”,“ value”:“ value1”},...]

example: 例:

function actionGetPageTitles(){
    echo '[ { "label": "Choice1", "value": "value1" }, { "label": "Choice2", "value": "value2" } ]';
    return true;
}

I think you must use a hidden field for assign the value 我认为您必须使用隐藏字段来分配值

for example 例如

echo $form->hiddenField($model,'school', array('id'=>"school", 'class' => 'login_txtbox')); 

then assign the value to the field 然后将值分配给该字段

'select'=>'js:function(event, ui) {

   $("#school").val(ui.item.value);

 }'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM