我想在Controller中获取post值,以便我像这样完成我的代码。 控制器看起来像这样
public function save_expense($id = NULL)
{
$data['amount'] = $this->input->post('amount',TRUE);
var_dump($data['amount'] );
print_r($data['amount']);
}
我的查看文件如下所示
<form class="col s12" enctype="multipart/form-data" action="<?php echo base_url();?>admin/transactions/save_expense/<?php if (!empty($expense_info)) { echo $expense_info->transactions_id;}?>" method="post">
<div class="row">
<div class="input-field col s12">
<input placeholder="Amount" type="text" required name="amount" id="amount" value="<?php if (!empty($expense_info)) {echo $expense_info->amount;}?>">
<label for="amount"><?= lang('amount') ?></label>
</div>
</div>
<div class="btn-area">
<button class="btn waves-effect waves-light " type="submit" name="action">Update </button>
</div>
</form>
我的.htaccess文件看起来像这样
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
我没有得到任何传递给控制器的价值,请帮我解决我的问题
答案 0 :(得分:1)
我测试了它并且工作正常。请参阅下面的代码并检查是否存在差异
HTML
<form class="col s12" enctype="multipart/form-data" action="<?php echo site_url();?>/extras/transactions/12333" method="post">
<div class="row">
<div class="input-field col s12">
<input placeholder="Amount" type="text" required name="amount" id="amount">
</div>
</div>
<div class="btn-area">
<button class="btn waves-effect waves-light " type="submit" name="action">Update</button>
</div>
</form>
PHP
function transactions($id = NULL){
echo "ID: ".$id;
echo "<br>";
echo "AMOUNT: ".$this->input->post('amount',TRUE);
}
输出