I have some data that I have to display as a table.
I think I should pass the data from the controller as $data['events'] = array(.....
and then load the view to display them.
<?php
$this->load->library('table');
echo $this->table->generate($events);
?>
this doesn't work though - it gives a Fatal error: Call to a member function generate() on a non-object
If I paste the same code in the controller, obviously using ->generate($data['events'] the table gets displayed correctly.
Should I get that views can't load libraries, or I am doing something wrong? Or maybe should I capture the output of the library in the controller and send that to the view?
You will load it using: $this->load->library('flavors/chocolate'); You may nest the file in as many subdirectories as you want. Additionally, multiple libraries can be loaded at the same time by passing an array of libraries to the load function.
Yes, but loading libraries where they're needed minimizes dependency issues.
All of the available libraries are located in your system/libraries/ directory. In most cases, to use one of these classes involves initializing it within a controller using the following initialization method: $this->load->library('class_name');
You don't access the model from the view. You access it from the controller and provides the output to the view.
If you need to call a library (and its functions) within a view, you can do this:
$CI =& get_instance();
$CI->load->library('library_name');
$CI->library_name->yourFunction();
You should run below code in the controller:
<?php
$this->load->library('table');
echo $this->table->generate($events);
?>
and store the data in variable and then send to the view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With