表未从Codeigniter中的数据库中获取数据。 [英] Table not fetching data from database in codeigniter..?

查看:39
本文介绍了表未从Codeigniter中的数据库中获取数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模型

function allDocs()
    {
        $query = $this->db->select('*')->from('docs')->get();
        return $query->result();
    }

控制器

public function viewauction()
    {
        $this->load->model('Crud_model');
        $data['query'] = $this->Crud_model->allDocs();   
        $this->load->view('index', $data);
    }

查看

<tbody>

                  <?php foreach($query as $row): ?>
                  <tr>   
                      <td><?php echo $row->doc_id; ?></td>
                      <td><?php echo $row->RefNo; ?></td>
                      <td><?php echo $row->MyNo; ?></td>
                      <td><?php echo $row->RegNo; ?></td>
                      <td><?php echo $row->LetterDate; ?></td>
                      <td><?php echo $row->LetterReceivedFrom; ?></td>
                      <td><?php echo $row->Subject; ?></td>
                      <td><?php echo $row->Title; ?></td>
                      <td><?php echo $row->Officer_InCharge; ?></td>
                  </tr>
                  <?php endforeach; ?>
</tbody>

我尝试了此操作。但是我没有得到查询的任何数据。

I tried this..but I dont get any data for "query".

错误显示
遇到PHP错误
严重性:注意

Error Shows A PHP Error was encountered Severity: Notice

消息:未定义变量:query

Message: Undefined variable: query

文件名:views / index.php

Filename: views/index.php

行号:277

回溯:

文件:C:\xampp\htdocs\1\application\views\index.php
行:277
功能:_error_handler

File: C:\xampp\htdocs\1\application\views\index.php Line: 277 Function: _error_handler

我也已经在索引中初始化了控制器。.
请帮助我。

I did initialize controller in index too.. please help me.

推荐答案

只要加载了特定视图,就应该加载控制器。

You should load the controller whenever the specific view is loaded.

public function dashboard()
{
        $this->load->model('Crud_model');
        $data = $this->Crud_model->allDocs();
        $this->load->view('index',['data'=> $data]); 
}

在这里,仪表板是控制器功能,在其中加载我所要访问的页面必须从数据库传递数据。我在这里编写了代码,以通过viewauction()方法中的模型获取数据。
因此,每当加载视图页面时,我都无法加载该控制器。

Here, Dashboard is the controller function in which I load the page in which I have to pass the data from database. I have written codes to fetch data through model in viewauction() method here. Thereby I failed to load this controller whenever I load the view page.

我的获取代码都是正确的,唯一我错过的是我没有

My code for fetching is all correct, and only thing I missed was that I didnt load in correct View Page.

此外,我也更改了此行

$this->load->view('index',['data'=> $data]);

谢谢大家的建议。

这篇关于表未从Codeigniter中的数据库中获取数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆