Header file in module

edited January 2015 in Modules
How to include header file in advance Module??

Comments

  • edited 4:08AM
    What kind of "header" file are you needing? To do this, you would probably need to create your own module that inherits from the Fuel_base_controller and call the parent::__construct() to validate the user, then create your own view file that renders as you need.
  • edited 4:08AM
    I have created advance module : banners
    /var/www/html/FUEL/fuel/modules/banners/libraries/Banners_base_controller.php
    function _render($view, $vars = array(), $return = FALSE, $layout = '')
    {

    $vars['body'] = $this->load->module_view(BANNERS_FOLDER, $view, $vars, TRUE);

    $layout = (! empty($layout) ) ? $layout : 'banners';
    $output = $this->load->view('_layouts/'.$layout, $vars, true);
    //$output = $this->load->view('_block/'.$block, $vars, TRUE);

    $this->load->module_library(FUEL_FOLDER, 'fuel_pages');
    $this->fuel_pages->initialize();
    $output = $this->fuel_page->fuelify($output);
    //return $output;
    if ($return)
    {
    return $output;
    }
    else
    {
    $this->output->set_output($output);
    }
    }
    /var/www/html/FUEL/fuel/modules/banners/models/banners_model.php

    function get_banners($where = array(), $order_by ='name', $limit = NULL, $offset = NULL, $return_method = NULL, $assoc_key = NULL)
    {
    //$lessons = $this->find_all($where, $order_by, $limit, $offset, 'array');
    //$this->db->select('*');
    //$this->db->from('banners_cats');
    //$this->db->where('published','yes');
    //$banners = $this->db->get()->result_array();
    $banners = $this->db->get($this->_tables['banners_cats'])->result_array();
    if($banners){
    foreach($banners as &$banner)
    {
    $banner['bannersmain'] = $this->db->where(array('banners_id' => $banner['id']))->get($this->_tables['banners'])->result_array();
    }
    }
    return $banners;
    }

    /var/www/html/FUEL/fuel/modules/banners/controllers/banners.php
    <?php
    //require_once(FUEL_PATH.'controllers/module.php');
    require_once(MODULES_PATH.'/banners/libraries/Banners_base_controller.php');
    class Banners extends Banners_base_controller {

    function __construct()
    {
    parent::__construct();
    $this->view_location = 'fuel';

    $this->load->module_model(BANNERS_FOLDER, 'banners_model');
    $this->load->module_model(BANNERS_FOLDER, 'banners_cats_model');
    //$this->load->module_model(COURSE_FOLDER, 'lessons_model');
    //$this->load->module_model(COURSE_FOLDER, 'articles_model');
    //$this->load->module_model(COURSE_FOLDER, 'authors_model');
    }

    function _remap()
    {
    $args = func_get_args();
    //print_r($args);
    $method = $args[0];
    $segments = $args[1];
    //print_r($segments);

    if($method == 'index')
    {
    $vars = array('page_title' => 'Banners');

    $vars['banners'] = $this->banners_model->get_banners();

    $vars['header'] = $this->load->view('_blocks/header',$vars,true);
    $vars['footer'] = $this->load->view('_blocks/footer',$vars,true);
    //$vars['footer'] = $this->load->view('_blocks/footer');

    //$this->fuel_page->add_variables($vars);
    $this->_render('banners', $vars);
    //$this->fuel->pages->render('banners', $vars, array('view_module' => 'banners'));
    }


    else{

    if(isset($segments[0]))
    {
    $this->lesson($segments[0]);

    }
    else{
    $vars = array('page_title' => 'Courses :: '.$method);
    $vars['course'] = $this->courses_model->find_one(array('slug' => $method), '', 'array');

    $vars['lessons'] = $this->lessons_model->get_lessons(array('course_id' => $vars['course']['id']), null, null, null, 'array');

    $this->_render('course', $vars);
    }
    }

    }




    }
    /var/www/html/FUEL/fuel/application/views/banners.php
    <?php $this->load->view('_blocks/header');?>
    I want to add /var/www/html/FUEL/fuel/application/views/_blocks/header.php in view file.


    Please replay me.
  • edited 4:08AM
    I'm sorry but I just don't quite understand the question. Perhaps an image or URL to reference what you are wanting? It looks like you are pulling in the header file as a $vars variable:
    $vars['header'] = $this->load->view('_blocks/header',$vars,true);
    If this is the case, the layout you specify can echo out a variable of $header to the page.

    I would probably do something similar to what you have:
    $vars['header'] = $this->load->view('_blocks/header', $vars,true); $vars['footer'] = $this->load->view('_blocks/footer', $vars, true); $this->fuel->pages->render('banners', $vars, array('view_module' => 'banners'));
    What are you seeing instead?
  • edited 4:08AM
    But I am getting error like this:

    A PHP Error was encountered
    Severity: Notice

    Message: Undefined variable: css

    Filename: core/Loader.php(332) : eval()'d code

    Line Number: 19
  • edited 4:08AM
    That is because the header file has $css in it and you aren't passing that as a variable. Try adding $vars['css'] = array();
  • edited 4:08AM
    thanks..
Sign In or Register to comment.