codeigniter - 从视图加载库? [英] codeigniter - loading a library from a view?
问题描述
我有一些数据,我必须显示为一个表。
我想我应该从控制器传递数据$ data ['events'] =数组(.....
,然后加载视图以显示它们。
<?php
$ this-> load-> library('table');
echo $ this-> table-> generate事件);
?>
错误:调用非对象上的成员函数generate()
如果我在控制器中粘贴相同的代码,显然使用 - > generate($ data ['事件']表格正确显示。
我应该得到视图不能加载库,或者我做错了什么?
或者我应该捕获控制器中库的输出并将其发送到视图?
<?php
$ this-> load-> library('table');
echo $ this-> table-> generate($ events);
?>
并将数据存储在变量中,然后发送到视图。
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 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.
这篇关于codeigniter - 从视图加载库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!