CodeIgniter新手求助:登录后无法加载home.php,提示$content.php加载失败
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
Correct your
v_home.phpview file
Open upapplication/views/v_home.phpand 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
$contentso CodeIgniter recognizes it as a variable, not a literal filename. - We don't need to add
.phpat the end—CodeIgniter automatically appends that when loading views.
- We remove the quotes around
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 (likeviews/home/), update the paths in your controller and view accordingly (e.g.,$isi['content'] = 'home/v_isi';).
Verify your controller logic
Your controller code looks good! You're correctly passing thecontentvariable to thev_homeview. 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

