Sasha
Sasha

Reputation: 8705

Same variable on every page

I have image path stored in DB (so it can be set by the user).

<?php $this->load->view('template/header'); ?>

load->view($main_content); ?> load->view('template/footer'); ?>

Image is in header and it is same for every page. At the moment I am inserting info about image in every controller. Is it possible to do that only once, because I need to load same model for every controller and then get the data?

Upvotes: 0

Views: 206

Answers (1)

kubilayeksioglu
kubilayeksioglu

Reputation: 498

You can create a render() function within a helper, which is basically:

function render($view_file, $data = array()){
    $CI =& get_instance();

    //get db data whatsoever
    $data = array();

    $CI->load->view('template/header');
    $CI->load->view($view_file, $data);
    $CI->load->view('template/footer');
}

Then, instead of loading files with $this->load->view($view_file, $data), you'd use render($view_file, $data) function.

Upvotes: 1

Related Questions