Yii2 迁移.表名中的百分号和括号 [英] Yii2 migrations. Percentage sign and brackets in table name
问题描述
我浏览了 github 上的 yii2-oauth2-server 代码,在 迁移文件.有问题的代码如下所示:
I browsed the yii2-oauth2-server code on github and encountered interesting syntax in the migration file. The code in question looks like this:
$this->createTable('{{%oauth_clients}}', [
...
], $tableOptions);
有人能解释一下 {{%oauth_clients}}
部分吗?表名用{{%..}}
括起来是什么意思?关于迁移的官方文档 对此一无所知,所有示例都有像这样的原始"表名:
Can someone explain the {{%oauth_clients}}
part? What does it mean when the table name is enclosed in {{%..}}
? The official documentation on migrations says nothing about it and all examples have the "raw" table names like this:
$this->createTable('post_tag', [
...
]);
我检查了我的数据库,创建的表好像没有括号,它的名字只是oauth_clients
.
I checked my database and the table was created as if there were no brackets, its name is simply oauth_clients
.
推荐答案
用于表前缀
来自 yii2 关于 Db 连接的文档:
如果表名是{{%TableName}}
,那么百分比字符 %
将替换为该属性值.例如,{{%post}}
变成 {{tbl_post}}
.
If a table name is given as
{{%TableName}}
, then the percentage character%
will be replaced with this property value. For example,{{%post}}
becomes{{tbl_post}}
.
这篇关于Yii2 迁移.表名中的百分号和括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!