7

出于某种原因,我似乎无法在 codeigniter 控制器中发布数据。我把它分解成一个非常简单的形式来测试它,仍然没有运气。如果我使用 method="get" 它工作正常。无论如何,下面是表单、控制器/函数和我的 .htaccess。任何帮助将非常感激。另外,我在这里看到了其他一些类似的问题,但似乎没有一个对我有用。

形式:

<form id="bundleOrderInfo" name="bundleOrderInfo" action="<?php echo(base_url()); ?>catalog/bundleSubmit" method="post"> 

<input type="text" name ="test" id="test" value="blahblah"></input>
<input type="submit"></input>
</form>

控制器/功能:

    public function bundleSubmit()
{
   $this->output->enable_profiler();
   $this->load->model('catalog_model');

   $data['availableCategories']=$this->catalog_model->getCategories();
   $data['availableItems'] = $this->catalog_model->getByCategory($data['availableCategories']);
   $testing = $this->catalog_model->formData();

   $this->load->view('templates/header');
   $this->load->view('templates/menu',$data);

   print_r($_POST);
}

.ht 访问:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /

   RewriteCond %{REQUEST_URI} ^system.*
   RewriteRule ^(.*)$ /ITPortal/index.php?/$1 [L]

   RewriteCond %{REQUEST_URI} ^application.*
   RewriteRule ^(.*)$ /index.php?/$1 [L]

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ ITPortal/index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /ITPortal/index.php
</IfModule> 
4

1 回答 1

6

动作应该直接指向控制器功能,如果你尝试 FormHelper 你的生活会容易得多

https://www.codeigniter.com/user_guide/helpers/form_helper.html

尝试在构造函数 [ __construct() 函数] 处加载模型、助手、库,这是一个很好的正确方法。

控制器

function __construct()
{
     parent:: __construct();
     $this->load->helper('form'); //loading form helper
     $this->load->model('catalog_model'); //loading your model
}

function bundleSubmit()
{
     $this->catalogmodel->insertFromForm();  //calling your method from model
}

通常你应该在模型中捕获 Posted Value

模型

  function insertFromForm()
  {
     $name= $this->input->post('name');
     print_r($name);
     die(); // stop the process here
  }

看法

<?php echo form_open('catalog/bundleSubmit','id="bundleOrderInfo" name="bundleOrderInfo"') ;?>
//you can also do this , this should be enough 
//<?php echo form_open('catalog/bundleSubmit')?>

<input type="text" name ="test" id="test" value="blahblah"></input>
<input type="submit" value="Submit"></input>

<?php echo form_close();?>

添加

'catalog/BundleSubmit' in form mean means your form posted values will goes to to 'controller/function()' and controller will redirect to a method in model 'model/insertDataFromForm"

如果您想了解更多信息,可以查看 CI 的目录

如何工作

https://www.codeigniter.com/user_guide/overview/appflow.html

更多信息:- https://www.codeigniter.com/user_guide/

于 2013-04-28T23:21:44.897 回答