You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter部分页面报HTTP ERROR 500问题求助

CodeIgniter HTTP ERROR 500 排查求助

部分页面(方法)可正常访问,但部分页面抛出 HTTP ERROR 500 错误,提示"This page isn’t working right now localhost can't currently handle this request"。即使在控制器中创建简单的search方法加载dummy视图,仍然触发该错误。

控制器代码

public function search() {
    $this->load->view('dummy');
}

视图(dummy.php)代码片段

<?php
if ($this->module_lib->hasActive('OPD')) {
    if ($this->rbac->hasPrivilege('opd_income_widget', 'can_view')) {
        ?>
        <div class="col-lg-2 col-md-3 col-sm-6 col20">
            <div class="info-box">
                <a href="<?php echo site_url('admin/patient/search') ?>">
                    <span class="info-box-icon bg-green"></span>
                    <div class="info-box-content">
                        <span class="info-box-text"><?php echo $this->lang->line('opd') . " " . $this->lang->line('income'); ?></span>
                        <span class="info-box-number"><?php
                            if (!empty($opd_income)) {
                                echo $currency_symbol . $opd_income;
                            } else {
                                echo "0";
                            }
                            ?></span>
                    </div>
                </a>
            </div>
        </div><!--./col-lg-2-->
        <?php
    }

.htaccess 配置

<ifModule mode_env.c>
    SetEnv CI_ENV development
</IfModule>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

排查步骤

  1. 开启CodeIgniter错误日志
    在application/config/config.php中设置:

    $config['log_threshold'] = 2;
    $config['log_path'] = APPPATH.'logs/';
    

    确保logs目录有写入权限,查看日志文件获取具体错误信息(500错误通常由PHP语法错误、未定义变量/类、权限问题引发)。

  2. 修复视图语法缺失
    提供的视图代码片段中,外层if ($this->module_lib->hasActive('OPD'))和内层if语句均未闭合,这会直接导致PHP语法错误触发500。补全闭合标签:

module_lib->hasActive('OPD')) { if ($this->rbac->hasPrivilege('opd_income_widget', 'can_view')) { // ... 现有HTML内容 ... } } // 补全外层if的闭合 ?>
3. **验证依赖项是否存在**
- 确认`module_lib`、`rbac`已通过`$this->load->library()`或自动加载配置正确加载
- 检查`$opd_income`、`$currency_symbol`变量是否在控制器中传递给视图,未定义变量若触发严格错误级别会导致500。

4. **查看PHP环境错误日志**
查看本地PHP环境的错误日志(如XAMPP的`apache/logs/error.log`、Linux的`/var/log/php/error.log`),获取更底层的错误提示。

5. **验证URL重写规则**
- 确认服务器已启用`mod_rewrite`模块
- 尝试直接访问`localhost/index.php/控制器名/search`,若能正常加载说明Rewrite规则存在问题;若仍报错则排除URL重写因素。

---
内容的提问来源于stack exchange,提问作者stikendra
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 22:30:49