php - 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 我添加了以下代码:
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;
}
});
(在这里找到:https ://github.com/codeigniter4/CodeIgniter4/issues/1661#issuecomment-453723931 )
当我导航时,它工作得很好。
但现在我想使用 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 打开标记之后添加 à 行,例如:
#!/usr/bin/env php
<?php
define('PUBFOLDER', str_replace('spark-', '', basename(__FILE__)));
并将 FCPATH 定义修改为:
define('FCPATH', __DIR__ . '/public' . DIRECTORY_SEPARATOR . PUBFOLDER . DIRECTORY_SEPARATOR);
有用。
推荐阅读
- python - 如何让 LSTM 捕捉每周的季节性?
- javascript - 重绘 Highchart 系列方法。Vuejs
- cross-compiling - 如何制作完整的 Yocto eSDK Sysroot 来进行 CMake 交叉编译?
- c - 在设置子收割机时,是否有一些关于如何使用 prctl() 的简短示例?
- node.js - npm 错误!notarget 找不到与 lodash@4.17.12-pre 匹配的版本
- sql - 使用 SQL 预测未来约会
- matlab - MATLAB 对象属性可见但不可修改
- html - 为弹性列中的滑动效果转换哪个属性
- c# - Xceed 标记化文本框搜索“开始于”
- c# - 只能在 IEnumerable 上调用 Cast 和 OfType