CodeIgniter Forums
Best place to have your view files? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Best place to have your view files? (/showthread.php?tid=61920)



Best place to have your view files? - lexxtoronto - 05-31-2015

I have no idea, but for some reason when I started my project [btw, my first project] I placed my view files inside a folder in the views folder, and now I have problems with routing:

- application
-----views
--------myviewfiles
-----------aboutus.php
-----------contactus.php

Shall I move them into the views folder or its ok to leave it as it is? Thanks


RE: Best place to have your view files? - includebeer - 05-31-2015

You can place your views in subdirectories without problems. This isn't the cause for your routing problems.

See http://www.codeigniter.com/userguide3/general/views.html#storing-views-within-sub-directories


RE: Best place to have your view files? - Muzikant - 05-31-2015

I do not understand your problem. If you have structure like so, you just call it by

PHP Code:
$this->load->view('myviewfiles/aboutus'); 

I do not see any problem with routing, because routing is related to controller, not a view.

If you did not, read the documentation. Good luck.


RE: Best place to have your view files? - lexxtoronto - 05-31-2015

Thanks guys, yes I'm calling them that way, it works no problem on my localhost, but when I go live Im having problems therefore I was wondering if I should move them to views.


RE: Best place to have your view files? - roopunk - 05-31-2015

Hey lexxtoronto ,
Can you elaborate what problem are you having with routing?
We are not able to relate routing with the views folder.


RE: Best place to have your view files? - mwhitney - 06-01-2015

(05-31-2015, 10:03 AM)lexxtoronto Wrote: Thanks guys, yes I'm calling them that way, it works no problem on my localhost, but when I go live Im having problems therefore I was wondering if I should move them to views.

Make sure the case of the filenames matches the way you call them in the code, especially if you are using Windows to develop your application and Linux (or anything but Windows) for the server. Additionally, check the permissions on the files to make sure your application can load them. Windows tends to be very forgiving on the case of filenames (because the filesystems commonly used on Windows are case-insensitive by default), but can be just as difficult (or even moreso) when dealing with permissions.

Personally, when I have some level of control on my server, or when I can ask my server's admins to do so, I add the user I use for uploading files to a group with the account used by the web server to run my application (usually www-data). Then I assign the appropriate permissions for the files/directories to that group, and they're less likely to be messed up when I add/update files (plus I don't have to give any more access than necessary to the outside world).


RE: Best place to have your view files? - lexxtoronto - 06-12-2015

Thank you


RE: Best place to have your view files? - musheertm - 09-17-2015

place your view files anywhere in views folder. categorize the files into sub directory is a good practice.