Welcome Guest, Not a member yet? Register   Sign In
navigation menu in header
#1

[eluser]selftaught[/eluser]
I am looking for advice to add a navigation menu in my header view so it is rendered on each page request. Sorry for the newby question.

site.php (controller)
<?php

class Site extends CI_Controller {

function contact_us()
{
$data['main_content'] = 'contact_us';
$this->load->view('template',$data);
}

function about_us()
{
$data['main_content'] = 'about_us';
$this->load->view('template',$data);
}
}

template.php (template)
<?php

$this->load->view('includes/header');

$this->load->view($main_content);

$this->load->view('includes/footer');

?>

header.php (included/header view)
<!DOCTYPE html>

&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" contnent="text/html; charset=utf-8"&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<p>This comes from the header view</p>

footer.php (included/footer view)
<p>This is the footer</p>
&lt;/body&gt;
&lt;/html&gt;

about_us.php (about_us view)
This is the about us page.about

Any help is greatly appreciated.

-Chris
#2

[eluser]ojcarga[/eluser]
@selftaught, could you please add [ code ][/ code ] (without spaces!) tags around the each file code? it more readable.
Thanks.
#3

[eluser]selftaught[/eluser]
site.php (controller)
Code:
&lt;?php

class Site extends CI_Controller {
  
  function contact_us()
  {
      $data[‘main_content’] = ‘contact_us’;
      $this->load->view(‘template’,$data);
  }
  
  function about_us()
  {
      $data[‘main_content’] = ‘about_us’;
      $this->load->view(‘template’,$data);      
  }
}
template.php (template)
Code:
&lt;?php

$this->load->view(‘includes/header’);

$this->load->view($main_content);

$this->load->view(‘includes/footer’);

?&gt;
header.php (included/header view)
Code:
<!DOCTYPE html>
  
&lt;html lang=“en”&gt;
&lt;head&gt;
  &lt;meta http-equiv=“Content-Type” contnent=“text/html; charset=utf-8”&gt;
  &lt;title&gt;untitled&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
This comes from the header view
footer.php (included/footer view)
Code:
This is the footer
&lt;/body&gt;
&lt;/html&gt;
about_us.php (about_us view)
Code:
This is the about us page.about

[/code]
#4

[eluser]ojcarga[/eluser]

And.. if you create a

menu.php (included/menu view)
Code:
<ul>
  <li><a href="#">Menu Item</a></li>
  <li><a href="#">Menu Item</a></li>
</ul>

and then, in the template.php (template) add ...

Code:
&lt;?php

$this->load->view(‘includes/header’);

//--
$this->load->view(‘includes/menu’);
//--

$this->load->view($main_content);

$this->load->view(‘includes/footer’);

?&gt;

Is not that functional for you?
#5

[eluser]selftaught[/eluser]
That should get me on my way. Thank you very much.

-Chris




Theme © iAndrew 2016 - Forum software by © MyBB