dongsibao8977 2016-12-31 18:58
浏览 31

Codeigniter的.htaccess中用于POST数据的规则

I've spent most of today trying to work out why my CodeIgniter application returns empty $_POST (and $this->input->post(<var>) and php://input) - I'd reduced the application down to a utterly minimal example of a single form input element and echoing $_POST.

As requested, the files (but, as far as I can see, this is irrelevant to my question of why the lack of the .htaccess rules prevents POST data being submitted through the framework):

The controller was this:

<?php
  class Form extends CI_Controller {
    public function __construct() {
      parent::__construct();
      $this->load->helper('form');
      $this->output->enable_profiler(TRUE);
    }

    public function form_show() {
      $this->load->view("form");
    }

    public function data_submitted() {
      $data['user_name'] = $this->input->post('u_name');
      $this->load->view("form-success", $data);
    }
  }
?>

form(.php) was:

<html>
<head></head>
<body>
<?php
  echo form_open('Form/data_submitted');
  echo form_label('User Name :', 'u_name');
  $form_data = array('name' => 'u_name');
  echo form_input($form_data);

  $submit_data = array(
    'type' => 'submit',
    'value'=> 'Submit',
  );
  echo form_submit($submit_data); ?>
  echo form_close();

  if(isset($user_name)){
    echo "<p>".$user_name."</p>";
  } ?>
</body>
</html>

form-success(.php) was

<?php var_dump($this->_ci_cached_vars); ?>
<html>
<head></head>
<body>
<?php print_r($_POST); ?>
</body>
</html>

I then realised I didn't have a .htaccess in my root folder - so restored CodeIgniter's default .htaccess file of

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 

But I can't work out which one of these (or why) allows POSTed data to be passed to the controller, but removing these rules doesn't allow it. Any light anyone can shed on this would be hugely appreciated to help satisfy my curiosity!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集