![]() |
Problem loading external view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Problem loading external view (/showthread.php?tid=13030) |
Problem loading external view - El Forum - 11-07-2008 [eluser]xzela[/eluser] Hi all, I'm having an issue loading a view from within a view. I continue to get a "An Error Was Encountered" error message when viewing any of the pages. Here is the source code to the view I'm trying to use: main_view.php Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> header.php Code: <?php Quote:An Error Was EncounteredIf i comment out the external views, everything seems to be working. And if i just view the header view by itself, it renders properly. Am I loading these view incorrectly? Is there a better (best practices) way to this? Let me know what you guys think. Thanks Problem loading external view - El Forum - 11-08-2008 [eluser]Derek Allard[/eluser] Is the header in a folder called "_global"? Based on your code comment Quote:/* Location: ./system/application/views/header_view.php */It doesn't look like it. Try creating a _global folder and copying header and footer into there and see what happens. Views can be nested into subfolders if you wish, and I use this technique myself often for organizational purposes. Problem loading external view - El Forum - 11-08-2008 [eluser]xzela[/eluser] Hi, Actually that comment in the code is incorrect. I will need to update that to reflect the most recent changes. The location of the header_view is actually at: Code: ./system/application/views/_global/header_view.php main_view is located at: Code: ./system/application/views/main_view.php Let me know what you guys think, Thanks again for the help Problem loading external view - El Forum - 11-08-2008 [eluser]m4rw3r[/eluser] ummm, header != header_view. You should call it header.php Problem loading external view - El Forum - 11-10-2008 [eluser]xzela[/eluser] Actually, I have an interesting update regarding this issue. If I change the location of the header.php file from: Code: ./system/application/views/_global/ Code: ./system/application/views/ Code: <?php In addition to this, changing the $this->load->view from: Code: $this->load->view('_global/header'); Code: include '_global/header.php'; will also work. So my question now is: Why wont the $this->load->view('_global/header') load when it's within a sub-folder in this particular case? Am I not specifying a top level directory or something? Let me know what you guys think, Thanks for the help so far. Problem loading external view - El Forum - 11-10-2008 [eluser]Derek Allard[/eluser] oh... wait a sec. change "_global" to "global". What happens? Problem loading external view - El Forum - 11-10-2008 [eluser]xzela[/eluser] Same deal either way. I renamed the '_global' directory to 'global' and the view still did not load. I even created a new directory called 'foo' and copied the header.php file to there and I got the same results. I have to clarify, is there another way to load external php files within a view? Perhaps I'm miss using the '$this->load->view()' feature and this is causing the real problem. Thanks for the help, much appreciated. Problem loading external view - El Forum - 11-10-2008 [eluser]Derek Allard[/eluser] hrm... thought it might be something else. Well, I'm totally dumbfounded. you should be able to use view within views no problem. If the original code you posted is accurate (you said you'd been moving some stuff around) and if "header.php" is actually in application/views/_global/header.php... then it makes no sense to me. I've just tested this (again) and it works for me. Could you try an even more minimal example. Problem loading external view - El Forum - 11-10-2008 [eluser]xzela[/eluser] Well, I think we found the issue, and I can't believe how lame this mistake was: I change the code from this: Code: $this->load->view('_global\header'); Code: $this->load->view('_global/header'); After changing the backslash to a forward slash it solved the problem. Thanks for the help everyone. It was much appreciated. |