[英]Cant get POST data in codeigniter controller
出於某種原因,我似乎無法在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);
}
的.htaccess:
<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>
動作應該直接指向控制器功能,如果你嘗試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
}
通常你應該在模型中捕獲已發布的值
模型
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.