Php CodeIgniter 4:spark与多个公用文件夹
我正在使用新的CodeIgniter 4(我使用了CodeIgniter 3)开发网站,但我遇到了一个问题: 我使用多个公用文件夹在1 CodeIgniter系统上运行多个网站,如:Php CodeIgniter 4:spark与多个公用文件夹,php,codeigniter,codeigniter-4,Php,Codeigniter,Codeigniter 4,我正在使用新的CodeIgniter 4(我使用了CodeIgniter 3)开发网站,但我遇到了一个问题: 我使用多个公用文件夹在1 CodeIgniter系统上运行多个网站,如: public/site1/index.php public/site2/index.php 等等 在index.php(来自CI4)中,我刚刚添加了以下行: define('PUBFOLDER',basename(_DIR__)); 在app/Config/Events.php中,我添加了以下代码: Event
public/site1/index.php
public/site2/index.php
等等
在index.php(来自CI4)中,我刚刚添加了以下行:
define('PUBFOLDER',basename(_DIR__));
在app/Config/Events.php中,我添加了以下代码:
Events::on('pre_system', function () {
$configs = Database::connect(PUBFOLDER)
->table('option')
->get()
->getResult();
foreach($configs as $config)
{
config('App')->{$config->option_name} = $config->option_value;
}
});
(请在此处找到:)
当我导航时,它工作得很好
但现在我想使用CLI和“spark”,在执行以下操作时:
php spark
我有一个逻辑错误:
Type: ErrorException
Message: Use of undefined constant PUBFOLDER - assumed 'PUBFOLDER' (this will throw an Error in a future version of PHP)
Filename: /home/www/ci4/www/app/Config/Events.php
那么,我如何告诉spark我想在“site1”中使用它呢
谢谢你的帮助 找到一个解决方案:我已将“spark”文件复制到“spark-site1”和“spark-site2”中 在这些文件中,我在PHP open标记后面添加了一行,如:
#!/usr/bin/env php
<?php
define('PUBFOLDER', str_replace('spark-', '', basename(__FILE__)));
它起作用了
define('FCPATH', __DIR__ . '/public' . DIRECTORY_SEPARATOR . PUBFOLDER . DIRECTORY_SEPARATOR);