0

I have a controller method that uses the table library:

public function index()
{
.....
$this->load->library('table')
....

and another method that generates the table using the table library:

function _generateTableHTML($tabledata)
{
....

The problem is that table library is only loaded in the index method, so when the _generateTableHTML() method is run it errors because it is missing the library.

Should I add $this->load->library('table') to the _generateTableHTML() method as well so it is loaded twice? Or is there a better way to load it so that it is available to all/both methods?

kittycat
  • 14,983
  • 9
  • 55
  • 80
dangel
  • 7,238
  • 7
  • 48
  • 74

1 Answers1

2
public function __construct()
{
    parent::__construct();
    $this->load->library('table');
}

You load the library in the constructor so it will be available to all the methods.

kittycat
  • 14,983
  • 9
  • 55
  • 80
  • Thanks, I see now that I've done that with my models already, but not constructors. Thanks again. – dangel May 26 '13 at 02:29