Welcome Guest, Not a member yet? Register   Sign In
[Solved] Custom Folder Structures
#1

[eluser]Anraiki[/eluser]
Prior to this topic, I was attempting to make a custom structure that divides Code Igniter into separate parts.

One for designer and the other is for developers.

The root folder consisted:

- index.php
- /application/
-- (code igniter stuff in the application folder)
- /template/


The application folder is the core of code igniter, while the template folder held the design part of code igniter.

Although we have the view files, I wanted to make the template folder in the top level of the ground without digging to deep from the root.

I was only half way successful in loading the files in the template folder but there was a problem: The inclusion of the objects in this folder did not inherit any variables or functions; it had its own scope.

In my controller file I have:
Code:
class Front extends Controller {

    function Front()
    {
        parent::Controller();    
    }
    
    function index()
    {

        $this->load->library('template');
        $this->template->load('index.php');

    }
}

In my template class:
Code:
class Template extends Controller {
    
    function load($object)
    {
        include('template/default/'.$object);
    }
    
    function get_header()
    {
        include('template/default/header.php');
    }
    
    function get_footer()
    {
        include('template/default/footer.php');
    }
    
}

Everything above works just fine however:

In my template's index file:
Code:
<?php $this->template->load('header.php'); ?>

<div id="content">
    <p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
</div>

&lt;?php $this->template->get_footer(); ?&gt;

The 1st line:
Code:
&lt;?php $this->template->load('header.php'); ?&gt;
Is called to a undefine object.

The simple question is: Does anyone know how to pass the helpers, libraries, variables, or functions into these included files?

Your help may revolutionized the way Code Igniter is used for development.

Thank you Smile
#2

[eluser]TheFuzzy0ne[/eluser]
Variables can be passed to a view as an array, via the second parameter of $this->load->view(), when you load a view using CodeIgniter's built-in loader. As you are directly including the pages, none of the CI variables exist within the view.

My suggestion would be to either a) extend the output class to your liking, or b), leave the views directory alone and simply create a shortcut to it named "template" for your own personal use. If you have no way to create a shortcut, I would suggest leaving things the way they were. CodeIgniter works great straight out of the box, but that's partly due to it's structure. If you re-organise the structure, you are likely to have a lot of problems.

However, it's possible to get a reference to the CI super object, by using:

Code:
$CI =& get_instance();

Then you could call on your template class like this:

Code:
$CI->template->load('header');
#3

[eluser]Anraiki[/eluser]
I went up to follow up on your code by referencing. It work only half way again Sad. $CI would be loaded with the Controller's function but it wouldn't load the "template library".

I am going to clarify what I want: "Code Igniter having the ability to load view files outside the view folders".

I will be right back with more results.

----
@7:14pm -8GMT
----

This shall fix all my problems and get rid of the insanity I am going through now.

In the Core Library, the Loader.php

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");
    }

Change the View Path Away!
#4

[eluser]Phil Sturgeon[/eluser]
Don't forget you can use relative paths in your view loading.

Code:
class Template extends Controller {
    
    function load($object)
    {
        $this->load->view('../template/default/'.$object);
    }
    
    function get_header()
    {
        $this->load->view('../template/default/header.php');
    }
    
    function get_footer()
    {
        $this->load->view('../template/default/footer.php');
    }
    
}




Theme © iAndrew 2016 - Forum software by © MyBB