I’m trying to extend my CI with a custom library that I plan on using for calculating the time value of money. The issue is whenever I load the class I get an internal server error, and I’m not quite sure why. Also, if there are any other suggestions, please let me know.
Thanks
Here is the controller where I’m trying to load the library.
class Timevalueshow extends Controller{
$params = array('years' => 0,
'rate' => 0,
'principle' => 0,
'periods' => 0,
'isCont' => true
);
$this->load->library('timevalue',$params);
function index(){
$this->load->view('Timevalueshow_view');
return true;
}
}
Here is the library, saved under application/libraries
class Timevalue{
private $years;
private $rate;
private $principle;
private $periods;
private $isCont;
//zeros to test
function Timevalue($params) {
$this->years = $params['years'];
$this->rate = $params['rate'];
$this->principle = $params['principle'];
$this->periods = $params['periods'];
$this->isCont = $params['isCont'];
}
//General Getters
function getYears(){
return $this->years;
}
function getRate(){
return $this->rate;
}
function getPrinciple(){
return $this->principle;
}
function getPeriods(){
return $this->periods;
}
//Factors
function FVFactor(){
if($this->isCont){
$new_rate = $this->rate / $this->periods;
$new_periods = $this->periods * $this->years;
return pow(1+$new_rate,$new_periods);
}
else{
return exp($this->rate*$this->years);
}
}
function PVFactor(){
if($this->isCont){
return pow($this->FVFactor(),-1);
}
else{
return pow($this->FVFactor(),-1);
}
}
//General Print
function leprint(){
echo "<br />Years: " . $this->years;
echo "<br />Rate(dec): " . $this->rate;
echo "<br />Principle: $" . $this->principle;
echo "<br /># of Periods: " . $this->periods;
echo "<br />isCont: " . ($this->isCont ? "True" : "False");
}
}
Your controller needs a constructor. It should look like this:
Only PHP5 uses the
__constructfunction. In PHP4 it should look like this: