Welcome Guest, Not a member yet? Register   Sign In
Best place to store functions?
#1

[eluser]imcl[/eluser]
I have a file I named includes.php that contains several functions, for example

Code:
function dayCount()
    {
        date_default_timezone_set('America/New_York');
        $j = array();
        for ($dayBegin = 1; $dayBegin < 32; $dayBegin++) {
            $j[$dayBegin] = $dayBegin;
        }
        return $j;
    }

    function yearCount()
    {
        date_default_timezone_set('America/New_York');
        $j = array();
        for ($yearBegin = 1922; $yearBegin < (date('Y')-18); $yearBegin++) {
            $j[$yearBegin] = $yearBegin;
        }
        return $j;
    }


// etc...

They are referenced mostly from view pages, and on occasion from a controller.

Ideally, where should this includes.php file go?

Should be in LIBRARIES or HELPERS? Does it make any difference?
#2

[eluser]bubbafoley[/eluser]
put it in a helper. the user guide explains it best:

"Unlike most other systems in CodeIgniter, Helpers are not written in an Object Oriented format. They are simple, procedural functions. Each helper function performs one specific task, with no dependence on other functions."
#3

[eluser]bubbafoley[/eluser]
also you'll need to rename the file to includes_helper.php to load it as a helper. then your controller can look like this:

Code:
$this->load->helper('includes');
$days = dayCount();
$years = yearCount();
#4

[eluser]imcl[/eluser]
thanks bubbafoley, i had seen that on the user guide and had actually tried to use the helper folder -- but nothing worked. perhaps it was an issue with the file name?

UPDATE - works perfectly now, thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB