Changing the Default View Directory |
[eluser]George36[/eluser]
Hi Folks, Can anyone tell me how I can change the default View directory? Many thanks George
[eluser]KingSkippus[/eluser]
I'm pretty sure that's hideously unsupported, but the view directory is defined in the file system/libraries/Loader.php. I think that what you'll have to do is either replace or extend the CI_Loader class as described in the Core Classes section of the User Manual. If I had to guess, and I haven't tested this so take it for what it's worth (Edit: Note reply below, I did test it and it works with 1.7.2 but not 2.0), I'd think that the best way to go would be to create a file named system/application/libraries/MY_Loader.php that is something like this: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Substitute your view directory name in for custom_view_dir. APPPATH is a constant that points to the system/application directory. (Or in CodeIgniter 2.0, just to application, which will be a peer directory of system.) I suppose that if you wanted it somewhere else entirely on the filesystem, you could remove APPPATH and put whatever absolute or relative directory you wanted there, as long as it's readable by your web server. Again, I haven't tried this, it's just a suggestion on a direction that might work. If I were you, I'd seriously consider using the default view directory. If you need to share a view library or something, you can use symbolic links to link your library to views. For exmaple (in your system/application directory): Code: sudo ln -s /path/to/view/library views
[eluser]KingSkippus[/eluser]
I just tried it, and the code above works under version 1.7.2. It doesn't work under the latest source of the upcoming 2.0, though. I don't know if that's a bug or if they plan on deprecating the ability to override the CI_Loader class. My guess is bug, but I haven't read through the bug reports or changelog in detail to know for sure. I still think that linking views to whatever directory you want to use is the way to go, though.
[eluser]WanWizard[/eluser]
2.0 has introduced the concept of packages, which has changed the way to loader works. Currently, packages work for libraries and models, I'm busy extending this to make it work for views and controllers as well. Which would give your application modularity without the need for HMVC, Matchbox, etc,
[eluser]mddd[/eluser]
I have been doing exactly what KingSkippus suggest: extending the loader to set the view directory. I realize it may work differently once CI 2.0 is here, but for now it works fine. I use it to put the views directory in the webroot. I have found it makes it much easier when working together with designers who work on the views. They don't have to get into the system folder at all.
[eluser]WanWizard[/eluser]
Agree. But your views shouldn't be in the system folder in the first place.
[eluser]KingSkippus[/eluser]
They're in system/application/views. I think WanWizard thought you meant system/views. In CodeIgniter 2.0, the system folder and application folder are peers, so it would be directly under application/views. Thanks for the 2.0 info, WanWizard. I'm just now starting to try out 2.0 on some of my sites and, like I said, haven't dug into it too much yet. Love the avatar, too. ![]()
[eluser]mddd[/eluser]
Aha, that would make sense. I hadn't meant it that way.
[eluser]clip[/eluser]
MY_Loader will still work with ci2.0, but you have to place it in the "application/core" folder instead of the usual "application/libraries" folder |
Welcome Guest, Not a member yet? Register Sign In |