views:

28

answers:

1

Hi guys. Can someone please tell me how to invoke a method from the codeigniter controller when the page loads? What I want to do is to fetch some data from database and put it inside meta tags before page actually load. I obviously want to do it inside header. It should be something like this:

method, which fetches some data from db and returns it
<meta property="og:title" content="<?php echo $returnedValue; ?>"/>

Can someone give me a hand with this one? Thanks.

+3  A: 

The page only loads after your controller loaded the view. So run your method before you call the view and add the result to the $data array, then load the view with the $data array as a parameter.

  public function index()
  {
    $data['returnedValue'] = yourMethod();
    $this->load->view('template', $data);
  }

Now $returnedValue, in the view, holds the return value of your method. echo it in the view wherever you want to include it.

tilman
ahh of course!! - thx mate :)
Pavel
no problem. sometimes it's the easy stuff that trips you..
tilman