Welcome Guest, Not a member yet? Register   Sign In
HOWTO: handle header and footer as modules (CI/blaze)
#1

[eluser]TheVoid[/eluser]
Hi,

I'm new to this community. This is my first post. Hi all!

I am working on a full restructuring of CodeIgniter/Blaze.
As it is build to work for anything, CI/blaze has lots of code that i don't need. And i also symplified the directories-structure.

Gz to the programmers! Great piece of codes!


My question is:

In my index.php file were everything starts (similar to CodeIgniter.php in the system-folder), everything works fine. All modules work fine. Website running fine.

My problem is the header and the footer. I got to many php-code, db-queries, ... in those template/view files.
I would like to handle the header and the footer as 2 new modules. As so; index.php would have to load first the header module, then the controller wich gets now loaded, and finally the footer controller.


So, i tryed Wink

This is the original code-part:

Code:
if ( ! file_exists(MODPATH.$RTR->fetch_module().'/controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) {
    show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}
include(MODPATH.$RTR->fetch_module().'/controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);

$class  = $RTR->fetch_class();
$method = $RTR->fetch_method();
if ( ! class_exists($class) OR $method == 'controller' OR substr($method, 0, 1) == '_' OR in_array($method, get_class_methods('controller'), TRUE) ) {
    show_404();
}

$CI = new $class();
if ( ! method_exists($CI, $method)) {
    show_404();
}
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
$OUT->_display();

This is how i thought it would work:
(but i'm a beginner when it comes to classes...)
Code:
if ( ! file_exists(MODPATH.'overall_header/controllers/overall_header'.EXT)) {
    show_error('Unable to load your overall_header controller.');
}
include(MODPATH.'overall_header/controllers/overall_header'.EXT);

if ( ! file_exists(MODPATH.$RTR->fetch_module().'/controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) {
    show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
}
include(MODPATH.$RTR->fetch_module().'/controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);

if ( ! file_exists(MODPATH.'overall_footer/controllers/overall_footer'.EXT)) {
    show_error('Unable to load your overall_footer controller.');
}
include(MODPATH.'overall_footer/controllers/overall_footer'.EXT);

$class  = $RTR->fetch_class();
$method = $RTR->fetch_method();

$HEADER = new overall_header();
$FOOTER = new overall_footer();
$CI = new $class();
if ( ! method_exists($CI, $method)) {
    show_404();
}

call_user_func_array(array(&$HEADER, 'index'), array_slice($URI->rsegments, 2));
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
call_user_func_array(array(&$FOOTER, 'index'), array_slice($URI->rsegments, 2));

$OUT->_display();


Guess it would have been too easy Wink

I get this error now:
Code:
Notice: Undefined property: overall_footer::$overall_header in C:\*****\libraries\loader.php on line 918

Fatal error: Call to a member function _assign_libraries() on a non-object in C:\*****\libraries\loader.php on line 918

I think by saying this:
Code:
$CI = new $class();
, you start a class for example 'page', if $class='page'.
And that class extends the controller class, so it loads with it everything that has been loaded/calculated before.

In my trial, i do that 3 times with 3 different modules.
But i don't know how to do it.


Sorry for the long post. Hope someone can/wants to help me.

Thanks in advance!


Messages In This Thread
HOWTO: handle header and footer as modules (CI/blaze) - by El Forum - 03-12-2009, 03:31 AM
HOWTO: handle header and footer as modules (CI/blaze) - by El Forum - 03-12-2009, 06:40 AM
HOWTO: handle header and footer as modules (CI/blaze) - by El Forum - 03-12-2009, 11:39 AM
HOWTO: handle header and footer as modules (CI/blaze) - by El Forum - 03-12-2009, 12:05 PM
HOWTO: handle header and footer as modules (CI/blaze) - by El Forum - 03-14-2009, 04:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB