Quy Hai Pham Thu Aug 25 05:05:42 -0400 2011

Subject: I want to use the database prefix. how ?

exam :
" tbl_users" -> model "tbl_users"
but i want "tbl_users " -> model "users"

like wordpress wp_users

thank you !


Clay vanSchalkwijk Wed Sep 07 17:14:42 -0400 2011

You can specify the table name in the model:

1 <?php
2 class User extends ActiveRecord\Model
3 {
4   static $table_name = 'wp_users';
5 }

You can't set a global prefix to all tables.

Ivan Zhuravlev Tue Nov 20 15:53:26 -0500 2012

sorry for necroposting, but I have an idea...

define('PREFIX','someprefix_');
define('TABLE_NAME',PREFIX.'tablename');
class User extends ActiveRecord\Model {
static $table_name = TABLE_NAME;
}

Bill Zhao Thu Nov 28 05:41:35 -0500 2013
1         static::$table_name = ActiveRecord\Utils::singularize(
2             substr(get_called_class(), strlen(self::NAME_PREFIX))
3         );
George V Fri May 09 15:32:01 -0400 2014

may be, in PHP >=5.3:

1)
define('PREFIX', 'myprefix_');

2)
class MyBaseModel extends \ActiveRecord\Model{
static $table_name;
public function __construct(){
self::$table_name = sprintf('%s%s', PREFIX, strtolower(get_called_class()));
}
}

3)
class MyCoolModel extends MyBaseModel{
public function _construct(){
parent::
_construct();
}
}

(1-4/4)