• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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!

#2
[eluser]TheFuzzy0ne[/eluser]
HEADER and FOOTER are being loaded as models, but they don't extend the model class.

#3
[eluser]TheVoid[/eluser]
In the main template file (here looking at double_column.php) i see this for including the header and footer:

Code:
<?php $this->load->view(false, 'themes/bb/layout/header'); ?>

Code:
<?php $this->load->view(false, 'themes/bb/layout/footer'); ?>



The only solution for modifying the header and footer i see, is adding php-code in the themes-header and -footer file.
But i dont like that way of fixing things.
Would be better if it works like the module 'page' for example. Where your functions have to be placed in the model file, and everything gets runned with its controller file + the output is set in the template file.

How would you do it then in my place?

Thanks for your time!

#4
[eluser]TheFuzzy0ne[/eluser]
I'm sorry but I'm not familiar with the inner-workings of blaze, as I don't use blaze. I assumed that this was your own code, so you could change what you wanted. I was simply trying to point out where I thought the problem might have been.

EDIT: Oh, and welcome to the CodeIgniter forums! Big Grin

#5
[eluser]TheVoid[/eluser]
Thanks Smile

Well, i know now where to look. Thanks.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.