Suppose I have a helper called “foobar” defined like this:
<?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:
<?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?
