Welcome Guest, Not a member yet? Register   Sign In
template/wrapper functionality
#1

[eluser]Unknown[/eluser]
I was wondering if there's any way in codeigniter to have a "heading" such as the top of this page that shows up on all pages automatically (sort of a template where I can put up menus and such and they will show up across the pages).

Maybe there isn't and there's a lot of coding involved or there is and I just haven't seen it, but if someone could help me out that'd be great. I started working with CI today and I think I'm getting a good grasp of it...
#2

[eluser]nmweb[/eluser]
There are a couple of layout libraries available in the wiki.
#3

[eluser]stuffradio[/eluser]
Yeah it is easy.

You have your application folders:
config
controllers
errors
helpers
hooks
language
libraries
models
views

In your controllers folder you will have the default controller. I have mine set to home, so I'll use that in this example. In my views folder I have a header and footer file.

This is an example of what my home class looks like.

Code:
<?php

class Home extends Controller {

  function Home()
  {
    parent::Controller();
  }

  function index()
  {
    $data['title'] = 'The title of my page';
    $data['header'] = 'The text in my header page';
    $this->load->view('header', $data);
    $this->load->view('home_view');
    $this->load->view('footer');
  }

In your header page you can just go something like
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<?php echo anchor('http://codeigniter.com', 'Code Igniter'); ?>

In your footer just close off body and html. In the other views just do all the stuff you normally would do for content.




Theme © iAndrew 2016 - Forum software by © MyBB