$this->input->post() 并且 $_POST 在 codeigniter 中为 NULL

$this->input->post() and $_POST is NULL in codeigniter

我在 codeigniter 中遇到问题,我有一个名为 view.php 的视图文件。

  <?php echo form_open('');?>
  <table class="table">
  <thead>
  <tr>
    <th>Full Name</th>
    <th>Username</th>
    <th>Action</th>
    </tr>
    </thead>

     <tbody>
      <tr>
      <td><?php echo form_input('fullname1',$row_data['fullname']);?>  </td>
      <td><?php echo form_input('username1',$row_data['username']);?></td>
         <td><?php echo anchor("welcome/save/".$row_data['rid'],form_button('button',"Save"));?></td>
  </tr>

    </tbody
   </table>
  <?php echo form_close();?>

这是我的保存方法

public function save($rid){
    $arr=array('fullname'=>$this->input->post('fullname1'),
                'username'=>$this->input->post('username1')
        );
        var_dump($_POST);
        var_dump($arr);

}

两个数组变量都给我 NULL 值,而文本框有值请帮助....谢谢

您需要将 url 添加到您的 form_open 方法中。尝试

echo form_open("your_url");

给出你的保存方法的路径而不是your_url。 还要检查文档 here

form_open 方法要求目标 url。

在视图中

 # Syntax <?php echo form_open('controllerName/MethodName');?>
 <?php echo form_open('welcome/save');?>

// remove this
<td><?php echo anchor("welcome/save/".$row_data['rid'],form_button('button',"Save"));?></td>

// Add this
 echo form_submit('mysubmit', 'Submit Post!');

在控制器中

public function save(){
    $fullname= $this->input->post('fullname1');
    $username = $this->input->post('username1');

    echo "MY name is ".$fullname." UserName Is : "$username;
}

阅读Form Helper Codeigniter and form-validation-using-codeigniter example