Welcome Guest, Not a member yet? Register   Sign In
Rename/move views directory
#1

[eluser]RyanStubbs[/eluser]
Hey.

I've started work on developing a blog/CMS system and I would like all of the theme files to be stored in /ROOT/themes/ instead of the (new/renamed) /ROOT/app/views/

Is it possible to do this because it would just mean that instead of using the conventional system, I could implement templates for the client to use.

Ryan.
#2

[eluser]davidbehler[/eluser]
You can use templates anyways.
Just create a subfolder in the app/views folder for every template you want the client to have.

e.g.
app/view/blue_power/
app/views/scifi_party/
app/views/rockin_template/

And when showing the view, just add the folder name to the parameter:
Code:
$this->load->view('folder_name/view_name');
#3

[eluser]RyanStubbs[/eluser]
I'd rather keep the theme system and the eyecandy away from the main app folder, to be honest.

But thanks. I'll see what I come up with.
#4

[eluser]xwero[/eluser]
the loader class set the view path so if you are naughty you can do
Code:
$this->load->_ci_view_path = 'some/directory';
But you better extend the loader class and create a method to manipulate the class variable.
#5

[eluser]tomcode[/eluser]
You can also use the $this->load->vars() together with $this->load->file().

$this->load->file() works like $this->load->view(), except it does not take vars and it uses the app root folder as start point.

Code:
// load the vars
$this->load->vars($data);

// load files from ./
$this->load->file('filepath/filename', true/false);
#6

[eluser]jedd[/eluser]
My themes are stored under /assets. At the moment they're a bit dodgy, as I organised them the wrong way around - theme name should be higher in the hierarchy rather than replicated lower in multiple hierarchies. But it serves as a workable example.

My default view file (used for displaying every page) includes this preamble:
Code:
<html>
<head>
<?php
    // $theme is set in MY_Controller, taken from session variable
    echo "\n". link_tag('assets/stylesheets/COMMON.css');
    echo "\n". link_tag('assets/stylesheets/'. $theme .'.css');

    // favicon being themed is of .. lesser usefulness, but, hey, why the heck not?
    echo "\n". link_tag('assets/icons/'.  $theme .'/FAVICON.png', 'shortcut icon', 'image/ico');
?>



MY_Controller mechanism is used to set the theme as part of the session userdata - this is set at login(), but I cater for a default theme here (note the reference back to the config.php file - one line entry there for default theme)
Code:
class MY_Controller  extends  Controller  {
    function MY_Controller ()  {
        parent::Controller();

        // We need a theme, any theme!  If we don't have one set, set one.
        if ($this->session->userdata("theme") == NULL)
            $this->session->set_userdata ("theme", $this->config->item('pdb_default_theme'));
        $this->data['theme'] = $this->session->userdata('theme');

Note the last line there pushes the chosen theme into the $this->data array that will end up feeding the view (above). I occasionally use $this->data['theme'] elsewhere - though as it happens, not as often as I expected - most stuff happens in the CSS. The places I use it most are when prefacing anchors to icons and the like.


Users can select a theme - they are named in the database table theme : [ id , name , longname , description ] - where 'name' refers to the subdirectory/ies in my assets structure. Obviously I have a int field in my user table to denote theme.id




Theme © iAndrew 2016 - Forum software by © MyBB