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

CodeIgniter新手求助:登录后无法加载home.php,提示$content.php加载失败

Fixing CodeIgniter's "Unable to load the requested file: $content.php" Error

Hey there, let's break down what's going wrong here and fix it quickly!

The Root Cause

That error message tells us exactly what's off: your view file (v_home.php) is trying to load a literal file named $content.php instead of using the dynamic value you passed from the controller. CodeIgniter can't find a file with that name, hence the error.

Step-by-Step Fix

  1. Correct your v_home.php view file
    Open up application/views/v_home.php and look for where you're trying to load the content. You probably have something like this (which is wrong):

    $this->load->view('$content.php');
    

    Replace it with this:

    <?php
    // Load the sidebar first
    $this->load->view('v_sidebar');
    // Load the dynamic content using the variable from your controller
    $this->load->view($content);
    ?>
    
    • We remove the quotes around $content so CodeIgniter recognizes it as a variable, not a literal filename.
    • We don't need to add .php at the end—CodeIgniter automatically appends that when loading views.
  2. Double-check file locations
    Make sure all your view files are in the right place:

    • v_home.php → application/views/
    • v_sidebar.php → application/views/
    • v_isi.php → application/views/
      If you're using subdirectories (like views/home/), update the paths in your controller and view accordingly (e.g., $isi['content'] = 'home/v_isi';).
  3. Verify your controller logic
    Your controller code looks good! You're correctly passing the content variable to the v_home view. No changes needed here.

Test It Out

Once you've updated v_home.php, reload the page—you should now see your sidebar and content loaded correctly without that error.

内容的提问来源于stack exchange,提问作者ariowishnu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:33:10