2013-04-28 13 views
7

何らかの理由で、私はcodeigniterコントローラーにデータを投稿できないようです。私はそれをテストするために非常にシンプルな形に壊しました、まだ運がありません。私がmethod = "get"を使うとうまく動作します。とにかく、以下はフォーム、コントローラ/関数、および私の.htaccessです。どんな助けでも大歓迎です。また、私はここでいくつかの同様の質問を見たが、誰も私のために働いた答えを持っていないようだ。codeigniterコントローラーでPOSTデータを取得する

形式:

<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ファイル:あなたの人生ははるかになりますFormHelperのあなたがしようとした場合

<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> 

答えて

6

アクションは、コントローラ機能に指示する必要がありより容易に

http://ellislab.com/codeigniter/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 
    } 

ビュー

で掲示される値をキャッチする必要があります追加

'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" 

あなたは物事が

http://ellislab.com/codeigniter/user-guide/overview/appflow.html

もっとに関する情報をどのように動作するか内容

のCIの表で確認することができ、よりお知りになりたい場合は

<?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();?> 

http://ellislab.com/codeigniter/user-guide/toc.html

+0

返信ありがとうございます、解決策は実際に私がApacheモジュールで書き直しをしなかったことになりました(奇妙なことに、データの投稿以外はすべてが機能するようです)。とにかく、提案のおかげで、私は間違いなくユーザーガイドに詳細を読む必要があります。 – Mike

+0

あなたはそれが働いていることを知ってうれしい。 :) –

関連する問題