Welcome Guest, Not a member yet? Register   Sign In
query database in all pages
#1

[eluser]keithics[/eluser]
Hello Guys,

I have a website which has a header in all pages. This header has to query (using a model) from a database like getting all the product categories and display it as a drop down (in the header).

The question is.. how can I get the categories without having to put $this->posts_model->get_cat() in all functions and classes?

note: model is autoloaded.
#2

[eluser]Bart v B[/eluser]
Add in youre constructor what you need.

Code:
function __construct() {
        parent::Controller();
        $data['dropdown'] = $this->posts_model->get_cat();        
    }

function index()
{

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

}

function Other()
{
  $this->load->view('other', $data);
}
#3

[eluser]n0xie[/eluser]
You mean:
Code:
function __construct() {
        parent::Controller();
        $this->data['dropdown'] = $this->posts_model->get_cat();        
    }

function index()
{

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

}

function Other()
{
  $this->load->view('other', $this->data);
}
#4

[eluser]Bart v B[/eluser]
[quote author="n0xie" date="1271699801"]You mean:
Code:
function __construct() {
        parent::Controller();
        $this->data['dropdown'] = $this->posts_model->get_cat();        
    }

function index()
{

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

}

function Other()
{
  $this->load->view('other', $this->data);
}
[/quote]

sorry that's what i mean Wink
forgot the $this-> by typeing a fast reply
#5

[eluser]keithics[/eluser]
thanks guys!




Theme © iAndrew 2016 - Forum software by © MyBB