0

我想像在运行时一样动态创建配置文件。我有一个Settings在数据库中命名的表。它的结构是这样的:

|Column     |Type    |Length|
|id         |int     |11    |
|key        |varchar |100   |
|value      |varchar |255   |
|created_at |datetime|      |
|updated_at |datetime|      |

现在当应用程序第一次启动时,它应该检查它是否连接到数据库。如果没有,则应将其重定向到该installer页面。用户将在其中输入必要的详细信息,并将相应地生成配置文件,并将相同的数据存储在Settings表中以供将来使用。

我不想将任何值硬编码到配置文件中。那么,我怎样才能完成这个任务呢?有任何想法吗?

我想到了一个主意。如果我检查文件中是否有使用 valueparams-local.php调用的参数。如果它存在,我们说应用程序已成功安装,否则我们将用户带到页面。installedtrueinstaller

4

1 回答 1

1

You can always use closures (anonymous functions) to get any kind of params you want to any place you desire.

See here: Multi Tenant Multiple Database Setup

What I would do is to use a caching server like memcached, make sure you cache the values after you read them from the DB, you really do not want the same queries to be run over and over again. Afterwards use a closure to merge the data that you have read and cached from the DB to any default values you have while still using the same config files.

If you really want to speed things along in your index.php file, when reading the config you can create your own config array any way you desire (I would still use memcached) and start the application with that config. The config files are basically just arrays that are used when starting the application.

1 thing, you probably cannot use any yii specific functions in either place because the Yii application will be available until after you start it (with a config I mean) so you might have to create the functions in PHP directly.

于 2015-01-27T02:24:09.627 回答