2016-08-01 41 views
0

我瀏覽了github上的yii2-oauth2-server代碼,並在migration file中遇到了有趣的語法。有問題的代碼是這樣的:Yii2遷移。表名中的百分號和括號

$this->createTable('{{%oauth_clients}}', [ 
     ... 
    ], $tableOptions); 

有人可以解釋{{%oauth_clients}}部分?當表名被包含在{{%..}}中時,意味着什麼?該official documentation on migrations隻字未提它和所有的例子有這樣的「原始」表名:

$this->createTable('post_tag', [ 
     ... 
    ]); 

我檢查我的數據庫和創建表,就好像沒有支架,它的名字簡直是oauth_clients

+0

我可能是錯的,但我懷疑這是用表前綴做,例如:app_oauth_clients –

+1

@eskimo看來你是對的,我發現[換個問題](http://stackoverflow.com/questions/28998385/yii2-gii-table-prefix)關於Gii並且在ActiveRecord類中使用了相同的語法,似乎是合乎邏輯的。 –

回答

3

是用於表前綴

從yii2 documentation on Db connection

如果一個表名作爲{{%TableName}},則該百分比 字符%將與這個屬性值來代替。例如, {{%post}}變成{{tbl_post}}