1

我正在尝试在 Codeigniter 中使用 PHP ActiveRecord。

我有一个这样的模型:

<?php class tblAdmins extends ActiveRecord\Model {} 

在我的控制器中,我有这个:

class Welcome extends CI_Controller {

        function __construct() {
        parent::__construct();
        $this->load->spark('php-activerecord/0.0.2');
    }

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
         $name = tblAdmins::find_by_username('myname');
        /*$this->load->view('welcome_message');*/
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

在 CodeIgniter 中打开页面时出现此错误:

致命错误:C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\ 中未捕获的异常 'ActiveRecord\DatabaseException' 与消息 '42S02、1146、表'CampusRecMobile.tbl_admins' 不存在' php-activerecord\lib\Connection.php:313 堆栈跟踪:#0 C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\adapters\MysqlAdapter.php(25 ): ActiveRecord\Connection->query('SHOW COLUMNS FR...') #1 C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php (254): ActiveRecord\MysqlAdapter->query_column_info(' tbl_admins') #2 C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(370): ActiveRecord\Connection->columns('tbl_admins') #3 C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Cache.php(67): ActiveRecord{closure}() #4 C:\xampp \htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Table.php(370): ActiveRecord\Cache::get('get_meta_data-`.. 在 C:\xampp\htdocs \codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php 在第 313 行

而不是寻找 CampusRecMobile。tblAdmins它正在寻找 CampusRecMobile.tbl_admins (这不是一个表)。我怎样才能摆脱这个下划线?

4

1 回答 1

2

您可以告诉 AR 模型使用哪个表

static $table_name = "tblAdmins";
于 2012-05-10T18:49:02.170 回答