Reputation: 876
Good day everyone. I just wanna know if it's possible to do computations inside a model, disregarding the database? If it is, how will I do it? If not, can someone explain? Thanks.
Example:
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;
}
Upvotes: 0
Views: 189
Reputation: 42450
Models are just regular classes - you write methods to do your calculation and then call them from the controllers as needed. See example below:
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);
}
}
Upvotes: 1