写入database.php并在codeigniter中创建文件

我正在尝试使用代码将config语句添加到config-&gt; database.php中,如何添加语句到 配置文件并在每次注册租户时创建新的连接组。 如何在codeigniter中写入文件?</ p>

我想在创建租户后动态地将以下语句添加到database.php:</ p>

< / p>





  $ db ['uup'] ['hostname'] ='localhost';

$ db ['uup'] ['username'] ='root';

$ db ['uup'] ['password'] ='';

$ db ['uup'] ['数据库 '] ='uup';

$ db ['uup'] ['dbdriver'] ='mysql';

$ db ['uup'] ['dbprefix'] ='';

$ db ['uup'] ['pconnect'] = TRUE;

$ db ['uup'] ['db_debug'] = TRUE;

$ db ['uup'] ['cache_on '] = FALSE;

$ db ['uup'] ['cachedir'] ='';

$ db ['uup'] ['char_set'] ='utf8';

$ db ['uup'] ['dbcollat​​'] ='utf8_general_ci';

$ db ['uup'] ['swap_pre'] ='';

$ db ['uup'] [' autoinit'] = TRUE;

$ db ['uup'] ['stricton'] = FALSE; </ code> </ pre>

</ div>

</ div> \ r

</ div>

展开原文

原文

I am trying to add the config statements using code into config->database.php, how to add statements to the config file and create a new connection group each time a tenant is registered. How to write to a file in codeigniter ?

I want to add the below statements dynamically to database.php once a tenant is created:

$db['uup']['hostname'] = 'localhost';
$db['uup']['username'] = 'root';
$db['uup']['password'] = '';
$db['uup']['database'] = 'uup';
$db['uup']['dbdriver'] = 'mysql';
$db['uup']['dbprefix'] = '';
$db['uup']['pconnect'] = TRUE;
$db['uup']['db_debug'] = TRUE;
$db['uup']['cache_on'] = FALSE;
$db['uup']['cachedir'] = '';
$db['uup']['char_set'] = 'utf8';
$db['uup']['dbcollat'] = 'utf8_general_ci';
$db['uup']['swap_pre'] = '';
$db['uup']['autoinit'] = TRUE;
$db['uup']['stricton'] = FALSE;

</div>

1个回答



您可以使用以下函数更新配置:</ p>

  $ this-&gt;  config-&gt; set_item('config_array_index','value_to_set'); 
</ code> </ pre>

但是,设置配置项仅适用于当前会话 - 它不会覆盖您的 实际上是codeigniter文件。</ p>

如果您希望永久性地使站点脱机,则需要某种持久存储,例如根据需要检查/更新的数据库中的值< / p>

Doc: http://codeigniter.com/user_guide/ libraries / config.html </ p>
</ div>

展开原文

原文

You can use below function to update configuration :

$this->config->set_item('config_array_index','value_to_set');

But, Setting a config item only applies to the current session - it does not overwrite your actually codeigniter files.

If you want to permanetly take a site offline, your'll need some sort of persistant storage, such as a value in a database that is checked/updated as needed

Doc: http://codeigniter.com/user_guide/libraries/config.html

dtdd25012
dtdd25012 有意思,会检查出来
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐