Welcome Guest, Not a member yet? Register   Sign In
Loading views from some other folder
#1

[eluser]magiclko[/eluser]
Hello

I was just wondering if i can load views from some folder other than application/views like say application/templates/<template-name> ?

Actually issue is that i want to introduce a template system in my web app. So, what i am thinking is that each template will have its views like header, footer, questions etc and given the template which the user select i will go in the appropriate folder and load that view. so, code will be like

Code:
$this->load->view(base_url().'application/templates/'.$templatename.'/footer');

Is it feasible? or there is a better way to do the same?
#2

[eluser]CroNiX[/eluser]
Why can't you do the same thing in the views directory?

-Application
--Views
---Theme1
----header.php
----footer.php
---Theme2
----header.php
----footer.php
Code:
$theme_name = 'Theme1';
$this->load->view($theme_name . '/footer')
Just store their theme choice in a cookie or something and if there isn't a cookie have a default.
#3

[eluser]magiclko[/eluser]
I can, i was just wondering if i could put template folder outside application folder. Can't i?
#4

[eluser]CroNiX[/eluser]
Not without some refactoring of CI code. Its not something you can set, just like the controllers have to be in the controllers directory.
#5

[eluser]magiclko[/eluser]
Ok. Thanks for your answers :-)
#6

[eluser]CroNiX[/eluser]
you can extend the CI_Loader and change your view path where it defaults to the APPPATH.'views/':
Code:
function CI_Loader()
{    
    $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE;
    $this->_ci_view_path = APPPATH.'views/';
    $this->_ci_ob_level  = ob_get_level();
            
    log_message('debug', "Loader Class Initialized");
}
Haven't tried it but looks like its all you would need to do.
#7

[eluser]magiclko[/eluser]
I think that won't help me either.. What i am looking for is that CI look in template folder(/template) and application/views folder too.. If i go with above code, than i guess i will end up with just one choice while i want both.
#8

[eluser]CroNiX[/eluser]
so make a template folder in your views folder?

-views
--header.php
--footer.php
--templates/
---header.php
---footer.php

$this->load->view('header');
$this->load->view('templates/header');
#9

[eluser]magiclko[/eluser]
Yeah, that's what i am gonna do now :-)




Theme © iAndrew 2016 - Forum software by © MyBB