Welcome Guest, Not a member yet? Register   Sign In
loading a helper in a library
#1

[eluser]tokyotech[/eluser]
I wrote my own DateForm library that creates HTML dropdowns of the months and days. I tried to do $this->load->helper('form') in its constructor but an error was given saying "load" was not defined. I suppose this is because only controllers are allowed to load helpers. But isn't it cumbersome to have to load the form helper every time I want to load my DateForm library?
#2

[eluser]BrianDHall[/eluser]
Code:
library class...
{
   private $ci;

   function __construct()
   {
       $this->ci =& get_instance();
      
       if (! function_exists(form_open))
       {
           $this-ci->load->helper('form');
       }
   }
}

This should allow your DateForm library to be independent, and will load the form helper on its own if it isn't already loaded.




Theme © iAndrew 2016 - Forum software by © MyBB