CodeIgniter Forums
Internal Server Error, when loading custom class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Internal Server Error, when loading custom class (/showthread.php?tid=32916)



Internal Server Error, when loading custom class - El Forum - 08-09-2010

[eluser]Unknown[/eluser]
I'm quite sure I followed the user guide, but I may be missing something. I have a custom class that I've placed in the app/lib folder and I think I'm calling it correctly, but the next page doesn't load when I load the class in the index function.

Here's the controller
Code:
<?php



    class Timevalueshow extends Controller{

        $this->load->library('timevalue');
        
        function index(){        
            
            $this->load->view('Timevalueshow_view');
            return true;
        }

    }

And the lib
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Timevalue{
    
        private $years;
        private $rate;
        private $principle;
        private $periods;
        private $isCont;
        
    
        //zeros to test
        function Timevalue(0,0, 0, 0, 0) {  
            $this->years = $years;  
            $this->rate = $rate;
            $this->principle = $principle;  
            $this->periods = $periods;
            $this->isCont = $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");
        }
    }

?&gt;



Internal Server Error, when loading custom class - El Forum - 08-09-2010

[eluser]WanWizard[/eluser]
You can't just put code anywhere within a class, only in class methods.
Code:
class Timevalueshow extends Controller
{
    function Timevalueshow()
    {
        $this->load->library('timevalue');
    }

    function index()
    {
        $this->load->view('Timevalueshow_view');
        return true;
    }
}