【问题标题】:how to post a form data to controller using GET method in codeigniter如何使用codeigniter中的GET方法将表单数据发布到控制器
【发布时间】:2012-03-28 10:48:40
【问题描述】:

我的看法:

<form action="<?=base_url()?>index.php/frontend/main_con/temp">
    <input type="text" name="temp">
    <input type="submit"/>
</form>

控制器:

function temp(){
    echo $_GET['temp'];
}

我无法访问此功能并且出现错误

遇到错误 您提交的 URI 包含不允许的字符。

那么,如何使用 GET 方法在控制器中传递表单数据? 提前谢谢。

【问题讨论】:

  • 我很好奇为什么你需要使用 GET 而不是 POST 来检索值?

标签: php codeigniter


【解决方案1】:

查看:

<form action="<?=site_url('controller_name/function_name);?>" method="get">
    <input type="text" name="temp">
    <input type="submit"/>
</form>

控制器

class controller_name extends CI_Controller{

   function function_name(){
      echo $this->input->get('temp');
   }

}

【讨论】:

    【解决方案2】:
    parse_str($_SERVER['QUERY_STRING'],$_GET);
    

    仅在我将以下行添加到 applications/config/config.php 后才为我工作:

    $config['uri_protocol'] = "PATH_INFO";
    

    【讨论】:

      【解决方案3】:

      要解决此错误,请转到this line。我个人认为,这是设计上的错误,因为 URI 中的黑名单符号比白名单要好得多。

      至于GET 变量.. 你必须使用&lt;form method="get" action="/what/ever/"&gt;

      【讨论】:

        【解决方案4】:

        【讨论】:

        • 为什么?据我所知,每个表单都必须通过 php 中的“post”和“get”方法发布。
        • 我一定不太理解“get”。当我在 CI 中工作并发布表单数据时,我总是使用 CI 方法 $this-&gt;input-&gt;post('temp'); 访问它。
        猜你喜欢
        • 2016-06-21
        • 2016-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-10
        • 1970-01-01
        • 1970-01-01
        • 2016-07-12
        相关资源
        最近更新 更多