我正在尝试在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中打开页面时出现此错误:
致命错误:未捕获异常'ActiveRecord \ DatabaseException' 消息'42S02,1146,表'CampusRecMobile.tbl_admins'没有 存在于 C:\ XAMPP \ htdocs中\笨\火花\ PHP-的ActiveRecord \ 0.0.2 \供应商\ PHP-的ActiveRecord \ LIB \ Connection.php:313 堆栈跟踪:#0 C:\ XAMPP \ htdocs中\笨\火花\ PHP-了activerecord \ 0.0.2 \厂商\ PHP-了activerecord \ lib中\适配器\ MysqlAdapter.php(25): ActiveRecord \ Connection-&gt;查询('SHOW COLUMNS FR ...')#1 C:\ XAMPP \ htdocs中\笨\火花\ PHP-了activerecord \ 0.0.2 \厂商\ PHP-了activerecord \ lib中\ Connection.php(254): ActiveRecord \ MysqlAdapter-&gt; query_column_info('
tbl_admins
')#2 C:\ XAMPP \ htdocs中\笨\火花\ PHP-了activerecord \ 0.0.2 \厂商\ PHP-了activerecord \ lib中\ Table.php(370): ActiveRecord \ Connection-&gt;列('tbl_admins
')#3 C:\ XAMPP \ htdocs中\笨\火花\ PHP-了activerecord \ 0.0.2 \厂商\ PHP-了activerecord \ lib中\ Cache.php(67): ActiveRecord {closure}()#4 C:\ XAMPP \ htdocs中\笨\火花\ PHP-了activerecord \ 0.0.2 \厂商\ PHP-了activerecord \ lib中\ Table.php(370): ActiveRecord \ Cache :: get('get_meta_data-`.. in C:\ XAMPP \ htdocs中\笨\火花\ PHP-了activerecord \ 0.0.2 \厂商\ PHP-了activerecord \ lib中\ Connection.php 在线313
而不是寻找CampusRecMobile。 tblAdmins 它正在寻找CampusRecMobile.tbl_admins(这不是一个表)。我该怎样摆脱这个下划线?
答案 0 :(得分:2)
您可以告诉AR模型使用哪个表
static $table_name = "tblAdmins";