Welcome Guest, Not a member yet? Register   Sign In
Relocate views folder
#1

[eluser]rolandpish[/eluser]
Hello.
First, I will explain our scenario.
Our web design developers use the following directory structure:
Code:
index.php
view_1.php
view_2.php
view_n.php
includes--/
          /include_header.php
          /include_footer.php
          /include_news.php
css-------/
          /css_1.css
          /css_2.css
js--------/
          /js1.js
          /jquery.js

We are thinking on migrating our projects to CodeIgniter keeping the same directory structure and I have a couple of questions:

1. Is it possible to relocate views so they reside at the root of the site instead of application/views folder?

2. Let's say that view_1.php has <? include_once('includes/include_header.php'); ?> and <? include_once('includes/include_footer.php'); ?>. This allows our web design developers to view view_1.php entirely (with header and footer) in their IDE.
Is it possible to keep the "include_once" commands in order to let them still have this "entire view" or do we have to use $this->load->view('includes/include_header') instead?

Thanks in advance
#2

[eluser]Dam1an[/eluser]
You probably could relocate the views to the web root by extending the loader class
You don't need to use load->view so ca carry on using includes in the views should you wish
#3

[eluser]rolandpish[/eluser]
Thanks Damian!

Another question: include_news.php shows the five more recent news. If I use the "include_once" command will I lose the "CodeIgniter mvc functionality" in that include?

PS: I'm still new in CodeIgniter. We're very close to start migrating all of our projects.

Thanks again.
#4

[eluser]Dam1an[/eluser]
If you have the db calls in there, yes
The MVC way to do that, would be to have a My_Controller (see user guide) which does the db calls via a model in its constructor, that way it executes the db queries on every page
You can then assign the news to a variable and use
Code:
$this->load->vars($data);
to make it available in your views
#5

[eluser]rolandpish[/eluser]
Excellent solution! thanks.

One last question. Where does this My_Controller must reside? on libraries folder?

Thanks for all your help!
#6

[eluser]TheFuzzy0ne[/eluser]
Yes, MY_Controler.php would go in ./system/application/libraries.
#7

[eluser]rolandpish[/eluser]
[quote author="Dam1an" date="1243033431"]You probably could relocate the views to the web root by extending the loader class[/quote]

Hi.
Do you have an example of a MY_Loader class which do this trick?

Thanks a lot!
#8

[eluser]Dam1an[/eluser]
I don't have an example, but taking a quick look in the Loader.php file, I think the part you want is in the constructor, where it sets the path to views, so all you should need to do is change that to what you want




Theme © iAndrew 2016 - Forum software by © MyBB