1
votes

I'm trying to use PHP ActiveRecord in Codeigniter.

I have a model like this:

<?php class tblAdmins extends ActiveRecord\Model {} 

In my controller I have this:

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 */

When open the page in CodeIgniter I get this error:

Fatal error: Uncaught exception 'ActiveRecord\DatabaseException' with message '42S02, 1146, Table 'CampusRecMobile.tbl_admins' doesn't exist' in C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php:313 Stack trace: #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-`.. in C:\xampp\htdocs\codeigniter\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Connection.php on line 313

Instead of looking for CampusRecMobile.tblAdmins it's looking for CampusRecMobile.tbl_admins (which is not a table). How can I get rid of this underscore?

1

1 Answers

2
votes

You can tell the AR Model which table to use

static $table_name = "tblAdmins";