如何在School模块视图中引入Univ模块的表单视图?
Hey there! Let's fix that view loading issue you're having. Your current attempt with $this->load->view('../univ/form'); isn't working because the relative path isn't pointing to the right place—when you're in the modules/school/views/ directory, ../ takes you up to modules/school/, so ../univ/form is looking for modules/school/univ/form which doesn't exist.
Here are the reliable ways to load the univ form view from your school module:
1. Use Module Name (HMVC Recommended)
If your project uses Modular Extensions HMVC (a common setup for CodeIgniter modular projects), you can directly reference the module's view by prefixing it with the module name:
$this->load->view('univ/form');
This tells CodeIgniter to look for the form.php file inside modules/univ/views/ automatically, which is clean and maintainable.
2. Full Path Reference (Non-HMVC)
If you're using a standard CodeIgniter setup without HMVC, you can use the full application path to target the univ view explicitly:
$this->load->view(APPPATH . 'modules/univ/views/form');
The APPPATH constant points to your project's application/ directory, so this ensures you're always pointing to the correct file regardless of where the calling view is located.
3. Corrected Relative Path (Not Recommended)
While it's possible to fix the relative path, it's less reliable if your directory structure changes later. For completeness, here's what the correct relative path would look like:
$this->load->view('../../univ/views/form');
This jumps up two levels from modules/school/views/ to modules/, then navigates into univ/views/form.php. But again, using the module name or full path is better practice.
Pick the method that fits your project's setup—HMVC's module name approach is the most straightforward if you have that extension installed.
内容的提问来源于stack exchange,提问作者Lemures

