简体   繁体   English

使用Smarty模板将数据从视图传递到控制器

[英]Passing data from view to controller using Smarty template

I downloaded an application and it is written using SMARTY TEMPLATE ENGINE . 我下载了一个应用程序,它是使用SMARTY TEMPLATE ENGINE编写的。 I am trying to create a search engine with drop down suggestion. 我正在尝试创建带有下拉建议的搜索引擎。

HTML code: HTML代码:

<input type="text" placeholder="{$_L['Search']}" id="txtsearch">

<div id="filter"></div> 

Javascript: Javascript:

 $( "#txtsearch" ).keyup(function() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){  
  filter = document.getElementById('filter').style.display="block";  

  userInput = encodeURIComponent(document.getElementById("txtsearch").value);  

 var _url = $("#_url").val();
 var urlsuggest = _url + 'ps/auto-suggest?userInput='+userInput;

  xmlHttp.open("GET", urlsuggest, true);  

  xmlHttp.onreadystatechange = handleResponse;  
  xmlHttp.send(null);  
  }else{  
  } 
});

Controller 控制者

  if(isset($_GET['userInput'])){
   $value = $_GET['userInput']; //assign the value
  }else{
   echo "no input";
  }

  $getdata = ORM::for_table('sys_items')->where_like('name',"%$value%")->order_by_asc('name')->find_many();

The problem is that the $value variable in the Controller is not getting the value which is passed in the var urlsuggest in the java script. 问题是Controller中的$value变量没有获取在Java脚本的var urlsuggest中传递的值。 When i add a default value in the $value variable for example $value="PRC" and change the var urlsuggest to _url + 'ps/auto-suggest' the code works fine and it will show all the data with the word "PRC" in the filter div. 当我在$value变量中添加默认值(例如$value="PRC"并将var urlsuggest更改为_url + 'ps/auto-suggest' ,代码工作正常,它将显示所有带有单词“ PRC”的数据在过滤器div中。

How can i pass the value of the input field to the $value variable in my Controller? 如何将输入字段的值传递给控制器​​中的$value变量? Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

You should use rawurldecode() because you are encoding with encodeURIComponent. 您应该使用rawurldecode(),因为您正在使用encodeURIComponent进行编码。 See the Manual 请参阅手册

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

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