I am trying to develop a website using a templating method I have created different files and would like to run a query and that query would be available on all templates is it possible to do that? Like I would like to give you an example what I am doing here in the controller I have created a variable like this
$data['navigation'] = 'templates/main_menu';
$this->load->view('main');
Okay so now here what I did in the view of main is I included header and footer there and called the navigation file dynamically like this
$this->load->view($navigation);
Okay so now What I am trying to do is want to get an icons stored in database and other settings as well so I placed a query in the header file
<?php $settings = $this->db->get_where('settings', array('id' => 2));\\ This query is just placed above the doctype in the header file and I would like to be called every where ?>
templates/main_menu.php
$settings->row()->header_bg_color
But I am getting an error as Message: Undefined variable: settings and if i place this settings query within the main_menu.php file it works so like what should be the way i mean it does not make sense to call the query again and again if I would be requiring what will be the best way to do and what is tthe use of model would it be used for the queries if it is then if I place this settings query within the model how would I access it is it possible please advise me
Thank you
hi below is code of controller. i have created the common_library.php file in which i have written all common function that I want to use all views.
class Maintenance extends CI_Controller {
function Maintenance() {
parent::__construct();
// file for all common function
include('application/controllers/common/common_library.php');
$this->load->model('maintenance_model');
$this->load->library('session');
$this->load->library('form_validation');
}
function index(){
/*
* @ desc : default function that loads the maintenance_view.
*
*
*/
$data['common_query'] = commonQuery() // define this function in common_library file
$data['model_data'] = $this->maintenance_model->projectdetail();
$data['formtitle'] = 'Maintenance List | BMS';
$this->load->view('maintenance_view',$data);
}
}