【问题标题】:Codeigniter - Call to undefined method CI_DB_mysql_driver::Codeigniter - 调用未定义的方法 CI_DB_mysql_driver::
【发布时间】:2010-04-02 14:26:11
【问题描述】:

当我尝试使用我的模型之一时,我收到此错误“致命错误:调用未定义的方法 CI_DB_mysql_driver::findVenueInfo()”。

我对这个锚有看法:

echo anchor('welcome/searchVenue/' . $row->venue_id, $row->venue);

它会生成如下链接:http://localhost/ci-llmg/index.php/welcome/searchVenue/1

调用的方法是

function searchVenue()
{
    $this->load->model('venues');
    //get venue info
    $data['info'] = $this->venues->findVenueInfo($this->uri->segment(3)); //this line generates the error

}

模型(venues.php)中的findVenueInfo函数为:

function findVenueInfo($id)
{
    $data = array();
    $this->db->where('id', $id);

    $Q = $this->db->get('venues');
    if ($Q->num_rows() > 0)
    {
        foreach ($Q->result() as $row)
        {
            $data[] = $row;
        }
    }

    $Q->free_result();
    return $data;
}

..但结果是致命错误:调用未定义的方法 CI_DB_mysql_driver::findVenueInfo() 我可能错过了一些愚蠢的东西,但无法让它工作!你怎么看?

【问题讨论】:

  • 已修复 - 我知道这很愚蠢 :) 控制器使用的是 $this->db->findVenueInfo 而不是 $this->venue->findVenueInfo。

标签: codeigniter


【解决方案1】:

您确定您项目根目录下的index.php 文件已在适当的位置包含引导程序

转到index.php 文件的末尾并在包含codeigniter.php 之前包含引导文件。

您的index.php 文件的结尾应如下所示。

/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 *

 * And away we go...
 *
 */

require_once APPPATH.'third_party/datamapper/bootstrap.php';

require_once BASEPATH.'core/CodeIgniter.php';

【讨论】:

    【解决方案2】:
    function findVenueInfo($id)
    {
        $data = array();
        $this->db->select()->from('venues')->where('id', $id);<----change it to
    
        $Q = $this->db->get();<----change it to
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result() as $row)
            {
                $data[] = $row;
            }
        }
    
        $Q->free_result();
        return $data;
    }
    

    【讨论】:

    • 函数 findVenueInfo($id) { $data = array(); $this->db->select()->from('venues')->where('id', $id);db->get( );num_rows() > 0) { foreach ($Q->result() as $row) { $data[] = $row; } } $Q->free_result();返回$数据; }
    • 考虑不是灰色背景的第一行
    【解决方案3】:

    我遇到了类似的错误,发现在 3.0 中我需要在 application/config/database.php 中启用 query_builder

    $query_builder = TRUE;
    

    【讨论】:

      猜你喜欢
      • 2012-01-03
      • 2015-10-16
      • 2012-02-06
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多