CodeIgniter中的表类和页面视图

Nan*_* HE 1 php frameworks module codeigniter view

我的欢迎控制器编码如下,

function index()
{
    // some code here to set up my table
    echo $this->table->generate();

    $data['heading'] = "My Real Heading";

    $this->load->view('view_page', $data);
}
Run Code Online (Sandbox Code Playgroud)

当我打开http://localhost/ci/index.php/welcome/

我发现表成功生成了.但是如何将我的桌子展示在我的标题下呢?我很困惑,表类由模块函数生成.它将在视图页面加载之前完成.这就是问题发生的原因.

[更新].

我发现echo $this->table->generate();可以进入我的视图页面.它现在有效.

Ros*_*oss 5

function index()
{
    // some code here to set up my table
    $data['myTable'] = $this->table->generate(); 
   //assign result to a variable in the $data array 

    $data['heading'] = "My Real Heading";

    $this->load->view('view_page', $data);
}
Run Code Online (Sandbox Code Playgroud)

在你看来:

<!-- html -->
echo $heading;
echo $myTable;
Run Code Online (Sandbox Code Playgroud)