I have an existing controller (classA) which needs to use a new helper class (classB). Typically I would place classB into a library and do
$this->load->library('classb');
$this->classb->method();
However, I've run into a problem where I am defining const's in my classB which are required by the constructor
classB {
const MYDEFINE = 1;
...
}
The problem with this approach is the definition of MYDEFINE is NOT available until I load the library, but I need to create the $params array with the arguments to send the classB constructor. So I get a case of chicken vs. egg
$params = array();
$params['open_mode'] = classB::MYDEFINE;
$instance = $this->load->library('classB', $params);
I've been able to solve this problem by not using a library - and instead using a @include_once('classB') in my classA controller which is working fine. The file classB.php is therefore stored in the controllers directory.
I'm wondering if others have run across this problem and how they might have solved it (other than by decaaring the consts elsewhere). I looked at a post by PhilSurgeon (http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY) on an alternative method but its not quite the right fit for this problem (at least I don't think so).