【发布时间】:2017-10-28 07:27:19
【问题描述】:
我正在尝试创建一个简单的计算器,它将通过单一方法执行计算
下面是我的控制器
类计算器扩展 CI_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$mid_cal = 0;
$total_cost = 0;
$this->load->view('Calculator',$total_cost,$mid_cal);
//print_r($total_cost);
}
public function calculate()
{
//print_r($_POST);
$qty_purchased = $this->input->post('qty_purchased');
$item_cost = $this->input->post('item_cost');
$mid_cal = $item_cost / $qty_purchased;
$qty_used = $this->input->post('qty_used');
$total_cost = $mid_cal * $qty_used ;
$this->load->view('Calculator',$total_cost,$mid_cal);
//$this->load->view('calculator');
}
}
以下是我的看法
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<html>
<body>
<form action="<?php echo base_url(); ?>index.php/calculator/calculate" method='post'>
Item:<br>
<input type="text" name="item" >
<br>
Qty Purchased:<br>
<input type="text" name="qty_purchased" >
<br>
Cost of Item:<br>
<input type="text" name="item_cost" >
<br>
Mid Cal:<br>
<input type="text" name="mid_cal" value="<?php echo $mid_cal ?>">
<br>
Qty Used:<br>
<input type="text" name="qty_used" >
<br>
Total Cost:<br>
<input type="text" name="total_cost" value="<?php echo $total_cost ?>">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
$total_cost 和 $mid_cal 的视图中出现未定义变量错误。我在计算函数中发送数据。我还尝试在我的索引函数中发送空白数据。我不知道如何解决这个问题。任何帮助都将受到欢迎。提前致谢。
【问题讨论】:
标签: php codeigniter