我试图从LocalConfiguration中取出我的数据库连接。但它并没有以这种方式运作。你有什么想法我能实现它吗?这就是我试图让它发挥作用的地方:
LocalConfiguration.php:
<?php
include_once 'databaseConn.php';
return [
'BE' => [
'debug' => false,
'explicitADmode' => 'explicitAllow',
'installToolPassword' => '$P$CcKE/MYkjKWDzNWsnVZhMBDAttVVrf.',
'loginSecurityLevel' => 'rsa',
],
并在databaseConn.php中:
<?php
$TYPO3_CONF_VARS['DB']['database'] = 'db_name';
$TYPO3_CONF_VARS['DB']['host'] = 'localhost';
$TYPO3_CONF_VARS['DB']['password'] = 'password';
$TYPO3_CONF_VARS['DB']['socket'] = '';
$TYPO3_CONF_VARS['DB']['username'] = 'usr_name';
希望你能帮助我。
感谢 克里斯
答案 0 :(得分:1)
在同一目录中创建名为AdditionalConfiguration.php
的文件。您可以通过直接解决它来覆盖那里的每个值
$GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = 'custom';
您也可以通过$context = GeneralUtility::getApplicationContext()->__toString();
检查ApplicationContext,它可以在.htaccess或vhost配置中设置
答案 1 :(得分:1)
在AdditionalConfiguration.php中使用以下代码:
$configurationSettings = array();
@include_once(__DIR__.'/DatabaseCredentials.php');
@include_once(… some other files …);
if (is_array($configurationSettings)) {
foreach ($configurationSettings as $path => $value) {
$GLOBALS['TYPO3_CONF_VARS'] = \TYPO3\CMS\Core\Utility\ArrayUtility::setValueByPath($GLOBALS['TYPO3_CONF_VARS'], $path, $value);
}
}
unset($configurationSettings);
然后在DatabaseCredentials.php中设置数据库凭据:
$configurationSettings = array_merge($configurationSettings, array(
'DB/database' => 'local_database',
'DB/username' => 'local_username',
'DB/password' => 'secret'
));
你已经完成了。
答案 2 :(得分:-1)
最好将数据库连接代码添加到&#34; LocalConfiguration.php&#34;。
return array(
'BE' => array(
'debug' => false,
'explicitADmode' => 'explicitAllow',
'installToolPassword' => '$P$CcKE/MYkjKWDzNWsnVZhMBDAttVVrf.',
'loginSecurityLevel' => 'rsa',
),
'DB' => array(
'database' => 'db_name',
'extTablesDefinitionScript' => 'extTables.php',
'host' => 'localhost',
'password' => 'password',
'socket' => '',
'username' => 'username',
),