Welcome Guest, Not a member yet? Register   Sign In
Loading Javascript once for all views?
#2

[eluser]CroNiX[/eluser]
Sounds like you need to break your view into 2 (or more) views.

The first view would be the header, which would contain everything in the <head> of your document. This would get loaded on all pages. It would probably be dynamic so you can pass the page title to it.

The other view would be your content, or everything within the <body>. You can create additional views for footers, menus, etc.

Then I'd create a library or a helper, so all you have to do is pass it the page title and "current" page data and it will automatically output the header and then the content to form a complete page.

Here's a simple helper...

Code:
function create_page($title = 'page title', $content = '')
{
  $CI =& get_instance();  //get CI superobject
  
  //grab the header view sending the page title to it
  $header_data['page_title'] = $title;
  $header = $CI->load->view('template/header', $header_data, TRUE);

  //now just send the header and content to CI's output class (so we can use caching if we want)
  $CI->output->set_output($header . $content);
}

When you're in a controller, now all you have to do is pass the function the page title, and the rendered view of your content by using the 3rd parameter of the load::view() method.

Code:
$view_data['some_var'] = 'something';
$current_view = $this->load->view('some_view', $view_data, TRUE);

//now send the page title and the rendered content view to the helper function...
create_page('my page title', $current_view);


Messages In This Thread
Loading Javascript once for all views? - by El Forum - 08-29-2012, 09:03 AM
Loading Javascript once for all views? - by El Forum - 08-29-2012, 09:40 AM
Loading Javascript once for all views? - by El Forum - 08-29-2012, 10:07 AM
Loading Javascript once for all views? - by El Forum - 08-29-2012, 01:39 PM
Loading Javascript once for all views? - by El Forum - 08-29-2012, 01:44 PM
Loading Javascript once for all views? - by El Forum - 08-29-2012, 02:00 PM
Loading Javascript once for all views? - by El Forum - 08-29-2012, 03:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB