Welcome Guest, Not a member yet? Register   Sign In
display same data from db automatically across multiple views - single function
#2

[eluser]techgnome[/eluser]
extend the base controller into a MY_Controller, put the code to pull the info into the constructor, then have your controllers extend that.

Here's an example of my MY_Controller that I use (CI2):
Code:
<?php
class MY_Controller extends Controller {
    
    var     $data = array();
  
    function __construct()
    {
        parent::Controller();    
        
        $this->data['content_view']     = '';
        $this->data['show_right_col']     = True;
        $this->data['css']                 = $this->config->item('css');
        $this->data['base']             = $this->config->item('base_url');
        $this->data['images']             = $this->config->item('images');
        $this->data['albumcovers']         = $this->config->item('albumcovers');
        
        $results = get_playing($this);
        
        $this->data['secondsremain']     = $results['secondsremain'];
        $this->data['nowplaying']         = $results['nowplaying'];
        $this->data['justplayed']         = $results['justplayed'];
        $this->data['upnext']             = $results['upnext'];
        $this->data['randompick']         = $results['randompick'];
        
    }
}

Then in my controllers you can see how I extend MY_Controller:
Code:
<?php

class Browse extends MY_Controller {

    function __construct()
    {
        parent::__construct();    
    }

And here's how I get the data, add to it and then pass it to the view:
Code:
$data = $this->data;
        $data['content_view'] = 'browse/browsemain';
        $data['show_right_col'] = false;
        
        $this->load->model("browse_model");
        $data['AlphaOptions']    = $this->browse_model->displayAlphaOptions();
        $data['YearOptions']    = $this->browse_model->displayYearOptions();
        
        $this->load->library('table');
        $this->load->helper('form');

        $this->load->view('template/template', $data);

-tg


Messages In This Thread
display same data from db automatically across multiple views - single function - by El Forum - 12-06-2010, 08:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB