Friday, 9 September 2016

yii2 table prefix

You put it in the config file, along with other db configuration, like this:
'db'=>array(
  'connectionString' => 'xxxxx',
  'username' => 'xxxxx',
  'password' => 'xxxxx',
  'tablePrefix' => 'tbl_',
),
All public properties of any component can be set in the config file this way.

You may change model class name AbcTest to User. And check Use Table PrefixGiigenerate correct model like that:
class Test extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }
    ...
}
In user method return '{{%user}}' if you check Use Table Prefix. If you not check Use Table Prefix in this method return 'tbl_user'.

yii2 table prefix

No comments:

Post a Comment