Welcome Guest, Not a member yet? Register   Sign In
Using Helper Functions Outside Controller
#1

[eluser]CmdrMoozy[/eluser]
Suppose I have a helper called "foobar" defined like this:

Code:
<?php if(!defined("BASEPATH")) exit("No direct script access allowed");

function getFoobar()
{
    return "Foobar";
}

?>

I add this helper to the list of automatically loaded helpers in config/autoload.php, and now in a controller, I want to do this:

Code:
<?php

$foobar = getFoobar();

class Foobar extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        echo $foobar;
    }
}

?>

The problem is that this fails, saying getFoobar() isn't defined (I assume this is because the loading of helpers and other things occurs when I call parent::__construct() in a controller).

How can I access helper functions outside of controllers?


Messages In This Thread
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 01:27 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 01:45 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 01:48 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 01:51 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 01:57 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 01:58 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 02:00 PM
Using Helper Functions Outside Controller - by El Forum - 11-10-2012, 02:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB