Yii2 迁移。表名中的百分号和括号

标签 yii2

我在github上浏览了yii2-oauth2-server代码,在migration file中遇到了有趣的语法。 。有问题的代码如下所示:

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

有人可以解释一下{{%oauth_clients}}部分吗? {{%..}} 中包含表名是什么意思? official documentation on migrations对此什么也没说,所有示例都有这样的“原始”表名称:

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

我检查了我的数据库,该表已创建,就好像没有括号一样,它的名称只是oauth_clients

最佳答案

用于表前缀

来自 yii2 documentation on Db connection :

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 迁移。表名中的百分号和括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38698129/

相关文章:

php - Yii2,如何使用另一个模型在 View 文件中显示

yii2 - 如何在 Yii 2 中使用 registerMetatag

php - 属性名称必须仅在 C :\xampp\htdocs\sample\vendor\yiisoft\yii2\helpers\BaseHtml. php 中包含单词字符

php - 在 yii2 gridview 中输入时进行过滤

php - 如何在 Yii2 中创建可重用的小部件

php - 根据 OOP 和 MVC 原则 (PHP),它是否正确?

yii - 如何在 yii2 的插入验证器上使用 required ?

javascript - 动态表单 + javascript

php - yii2 将同名输入插入数据库?