大家好日子。我只是想知道是否可以在模型中进行计算,而忽略数据库?如果是的话,我该怎么做?如果没有,有人能解释一下吗?感谢。
示例:
var $monthly = '';
var $annually = '';
var $quarterly = '';
var $semiannual = '';
function computation($price, $quantity){
$this->monthly = $price * $quantity;
$this->annually = $price * $quantity * 12;
$this->quarterly = $price * $quantity * 3;
$this->semiannual = $price * $quantity * 6;
}
答案 0 :(得分:1)
模型只是常规类 - 您编写方法来进行计算,然后根据需要从控制器中调用它们。见下面的例子:
class Circle extends CI_Model {
public function area($rad) {
return 3.14 * $rad * $rad;
}
}
class CircleCtrl extends CI_Controller {
public function calc_area() {
$this->load->model('Circle');
$area = $this->circle->area(10);
}
}